QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#366767#7185. Poor StudentsGiga_Cronos#TL 1ms3800kbC++205.4kb2024-03-25 07:23:272024-03-25 07:23:28

Judging History

你现在查看的是最新测评结果

  • [2024-03-25 07:23:28]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3800kb
  • [2024-03-25 07:23:27]
  • 提交

answer

///Giga_Cronos Template from UH Top


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC option("arch=native", "no-zero-upper") // Enable AVX
using namespace std;
///Macros
#define int long long
#define pb push_back
#define fs first
#define sc second
#define pf push_front
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define sz(x) (int)(x.size())
#define mid ((L+R)/2)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pii > vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef pair<vi,vi> pvv;
typedef __int128_t int128;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
///Constraints:
const int inf = ((1ll<<31ll)-1ll);
const long long INF = (((1ll<<60ll)-1ll)*2ll)+1ll;
const ull mod=998244353;
const ld pi = acos(-1);
const ld eps=1e-8;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lg2ll(x) 63ll - __builtin_clzll(x)
#define lgx(x,b) ( log(x) / log(b) )

/*#include<ext/pb_ds/assoc_container.hpp> // Common file
#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
//comenta el define long long int
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order
// order_of_key */
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

/// Quick Pow------------------------------------------------
int  qpow(int a, int b) {
int res = 1;
for (; b; b /= 2, a = (a*a)%mod) {
    if (b % 2) {
        res =(res*a)%mod;
    }
}
    return res;
}

int  qpow(int a, int b,int mod) {
int res = 1;
for (; b; b /= 2, a = (a*a)%mod) {
    if (b % 2) {
        res =(res*a)%mod;
    }
}
    return res;
}

///Inverso Modular
int InverM(int a,int b)
{
    int eso=a%b;
    if(eso==0)
        return 0;
    int ans=(1-(int128)b*InverM(b,eso))/eso;
    if(ans<0)
        ans+=b;
    return ans;
}
const int MAXN=50'005;
/// Variables-----------------------------------------------
int n,m,q,k;
set<pii> Pq[10][10];
int Stud[MAXN][10][10];
int Cap[10];
int Cant[10];
int sum=0;

inline pii C(int i,int j){
    pii ans={INF,-1};
    if(!Pq[i][j].empty()){
       ans=min(ans,*Pq[i][j].begin());
    }
    if(Cap[i]>Cant[i]){
        ans=min(ans,{0,-1});
    }
    return ans;
}
int cont=0;
bool BellmanFord(){
    vi D(k,0);
    cont++;
    vi P(k,-1);

    bool ok=false;
    int tipo=0;
    for(int i=0;i<=k;i++){
        ok=false;
        for(int j=0;j<k;j++){
            for(int h=0;h<k;h++){
                if(D[h]>C(j,h).fs+D[j]){
                    ok=true;
                    tipo=h;
                    D[h]=C(j,h).fs+D[j];
                    P[h]=j;
                }
            }
        }
    }
    if(!ok)return false;    
    vector<int> Ar;
    Ar.pb(tipo);
    int cur=tipo;
    for(int i=0;i<=k && cur!=-1;i++){
        cur=P[cur];
        Ar.pb(cur);
    }
    if(Ar.back()==-1){
        Ar.pop_back();
    }
    reverse(all(Ar));
    vi Flag(k);
    stack<int> S;
    int num=0;
    vi Cyc;
    for(auto u:Ar){
        if(Flag[u]){
            num=u;
            break;
        }
        S.push(u); 
        Flag[u]=1;
    }
    Cyc.pb(num);     
    while(S.top()!=num){
        Cyc.pb(S.top());
        S.pop();
    }
    for(int i=0;i<sz(Cyc);i++){
        int est=C(Cyc[i],Cyc[(i+1)%sz(Cyc)]).sc;
        sum+=C(Cyc[i],Cyc[(i+1)%sz(Cyc)]).fs;
        if(est!=-1){
           Cant[Cyc[i]]--;
           Cant[Cyc[(i+1)%sz(Cyc)]]++; 
           for(int h=0;h<k;h++){
             Pq[Cyc[i]][h].erase({Stud[est][Cyc[i]][h],est});
           } 
           for(int h=0;h<k;h++){
             Pq[Cyc[(i+1)%sz(Cyc)]][h].insert({Stud[est][Cyc[(i+1)%sz(Cyc)]][h],est});
           }
        }
    }
//       cout<<sum<<'\n';
//   for(int i=0;i<k;i++){
//     set<int> S;
//     for(int h=0;h<k;h++){
//         for(auto s:Pq[i][h]){
//             if(!S.count(s.sc)){
//                 cout<<s.sc<<' ';
//                 S.insert(s.sc);
//             }
//         }
//     }
//     cout<<'\n';
//   }


    return true;
}



void problem()
{
  cin>>n>>k;
  vvi Ns(n);
  for(int i=0;i<n;i++){
     vi F(k);
     for(int i=0;i<k;i++){
        cin>>F[i];
     }   
     for(int j=0;j<k;j++){
        for(int h=0;h<k;h++){
            Stud[i][j][h]=F[h]-F[j];
        }
     }
     Ns[i]=F;
  }
  
  for(int i=0;i<k;i++)cin>>Cap[i];

  for(int i=0;i<n;i++){
    vi F(k);
    iota(all(F),0);
    random_shuffle(all(F));
    for(auto j:F){
       if(Cant[j]<Cap[j]){
         Cant[j]++;
         sum+=Ns[i][j];   
         for(int h=0;h<k;h++){
             Pq[j][h].insert({Stud[i][j][h],i});
         }
         break;
       } 
    }
  }
  while(BellmanFord());
  cout<<sum<<'\n';
  
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
  //  freopen("a.in","r",stdin);
  //  freopen("a.out","w",stdout);

    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        problem();
        cout<<'\n';
    }

}



///Tips
//Busqueda Binaria
//Precomputing
//Dinamic Programming
//Revisar constraints

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

12


result:

ok answer is '12'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3800kb

input:

3 3
1 2 3
2 4 6
6 5 4
1 1 1

output:

8


result:

ok answer is '8'

Test #3:

score: -100
Time Limit Exceeded

input:

1000 10
734 303 991 681 755 155 300 483 702 442
237 256 299 675 671 757 112 853 759 233
979 340 288 377 718 199 935 666 576 842
537 363 592 349 494 961 864 727 84 813
340 78 600 492 118 421 478 925 552 617
517 589 716 7 928 638 258 297 706 787
266 746 913 978 436 859 701 951 137 44
815 336 471 720 2...

output:


result: