Submission #167412

# Submission time Handle Problem Language Result Execution time Memory
167412 2019-12-08T09:48:58 Z theStaticMind Kralj (COCI16_kralj) C++14
0 / 140
562 ms 131076 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
void merge_sort(vector<int>&A,vector<int>&B,int x){
      vector<int>ans;
      int ind=0;
      for(int i=0;i<A.size();i++){
            if(i==x)continue;
            while(ind<B.size()&&B[ind]<A[i])ans.pb(B[ind++]);
            ans.pb(A[i]);
      }
      while(ind<B.size())ans.pb(B[ind++]);
      swap(B,ans);
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n,ans=0;
      cin>>n;
      vector<int>A(n);
      vector<int>P(n);
      vector<int>V(n);
      vector<int>cnt(n,0);
      vector<int>ptr(n);
      for(int i=0;i<n;i++){
            cin>>A[i];A[i]--;
            cnt[A[i]]++;
            ptr[i]=i;
      }
      for(int i=0;i<n;i++){
            if(cnt[i]==0)continue;
            int c=cnt[i];
            int ind=i;
            while(c>0){
                  c--;
                  if(c==0)break;
                  ind++;
                  while(ptr[ind%n]!=ind%n)ind=ptr[ind%n];
                  c+=cnt[(ind)%n];
            }
            ptr[i]=(ind+1)%n;
            if(i<ptr[i])
            i=ptr[i];
            else break;
      }
      int mx=0,ind=-1;
      for(int i=0;i<n;i++){
            if(cnt[i]==0)continue;
            if(ptr[i]<=i){
                  if(mx<ptr[i]+n-i){
                        mx=ptr[i]+n-i;
                        ind=i;
                  }
            }
            else if(mx<ptr[i]-i){
                  mx=ptr[i]-i;
                  ind=i;
            }
      }
      for(int i=0;i<n;i++)cin>>P[i];
      for(int i=0;i<n;i++)cin>>V[i];
      vector<int> data[n];
      for(int i=0;i<n;i++){
            data[A[i]].pb(V[i]);
      }
      for(int i=0;i<n;i++)sort(all(data[i]));
      for(int k=0;k<n;k++,ind=(ind+1)%n){
            int i=upper_bound(all(data[ind]),P[ind])-data[ind].begin();
            if(i==data[ind].size())i=0;
            else ans++;
            merge_sort(data[ind],data[(ind+1)%n],i);
      }
      cout<<ans;
}

Compilation message

kralj.cpp: In function 'void merge_sort(std::vector<long long int>&, std::vector<long long int>&, long long int)':
kralj.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<A.size();i++){
                   ~^~~~~~~~~
kralj.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(ind<B.size()&&B[ind]<A[i])ans.pb(B[ind++]);
                   ~~~^~~~~~~~~
kralj.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       while(ind<B.size())ans.pb(B[ind++]);
             ~~~^~~~~~~~~
kralj.cpp: In function 'int32_t main()':
kralj.cpp:78:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(i==data[ind].size())i=0;
                ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 426 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 430 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 439 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 439 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 404 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 473 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 543 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 502 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 562 ms 131072 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 471 ms 131072 KB Execution killed with signal 9 (could be triggered by violating memory limits)