Submission #428406

#TimeUsernameProblemLanguageResultExecution timeMemory
428406AmylopectinGondola (IOI14_gondola)C++14
100 / 100
30 ms2980 KiB
#include <iostream> #include <stdio.h> #include <algorithm> #include "gondola.h" //#include "grader.cpp" using namespace std; const long long mxn = 2e6 + 10,mo = 1e9 + 9; struct we { long long stn,thn; }; bool cmp(const struct we &l,const struct we &r) { return l.thn < r.thn; } struct we so[mxn] = {}; int u[mxn] = {}; int valid(int n, int inp[]) { long long i,j,m,stp = -1,of = 0; for(i=0; i<n; i++) { if(stp == -1 && inp[i] <= n) { stp = i - inp[i] + 1; if(stp < 0) { stp += n; } } if(stp >= 0 && inp[i] <= n) { if((stp + inp[i] - 1) % n != i) { of = 1; break; } } } for(i=0; i<n; i++) { if(u[inp[i]] == 1) { of = 1; break; } else { u[inp[i]] = 1; } } if(of == 0) { return 1; } return 0; } int replacement(int n, int inp[], int ans[]) { long long i,j,ru = 0,stp = -1,fr,ba,rua = 0; for(i=0; i<n; i++) { if(stp == -1 && inp[i] <= n) { stp = i - inp[i] + 1; if(stp < 0) { stp += n; } break; } } if(stp == -1) { stp = 0; } for(i=0; i<n; i++) { if(inp[i] > n) { so[ru] = {(i + n - stp) % n + 1,inp[i]}; ru ++; } } sort(so,so+ru,cmp); fr = 0; ba = 0; // while(ba < ru) // { // } for(i=n+1; i<=so[ru-1].thn; i++) { if(i == so[fr].thn) { ans[rua] = so[fr].stn; rua ++; fr ++; // if(ba < fr) // { // ba = fr; // } } else { ans[rua] = so[fr].stn; so[fr].stn = i; rua ++; } } return rua; } int countReplacement(int n, int inp[]) { long long i,j,m,stp = -1,of = 0,ans = 1,be,ru = 0,off = 0,cva,cdif,fva; for(i=0; i<n; i++) { if(stp == -1 && inp[i] <= n) { stp = i - inp[i] + 1; if(stp < 0) { stp += n; } } if(stp >= 0 && inp[i] <= n) { if((stp + inp[i] - 1) % n != i) { of = 1; break; } } } // for(i=0; i<n; i++) // { // if(u[inp[i]] == 1) // { // of = 1; // break; // } // else // { // u[inp[i]] = 1; // } // } if(of == 1) { return 0; } if(stp == -1) { off = 1; ans *= n; stp = 0; } for(i=0; i<n; i++) { if(inp[i] > n) { so[ru] = {(i + n - stp) % n + 1,inp[i]}; ru ++; } } sort(so,so+ru,cmp); be = n; for(i=0; i<ru; i++) { if(so[i].thn == be) { return 0; } cdif = so[i].thn - be - 1; cva = ru-i; j = 0; while(1) { fva = (1 << j) & cdif; if(fva > 0) { ans *= cva; ans %= mo; } j ++; cva = cva * cva; cva %= mo; fva = (1 << j); if(fva > cdif) { break; } } // for(j=be+1; j<so[i].thn; j++) // { // ans *= ru-i; // ans %= mo; // } be = so[i].thn; } return ans; // return -3; } //int main() //{ // // return 0; //}

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:20:17: warning: unused variable 'j' [-Wunused-variable]
   20 |     long long i,j,m,stp = -1,of = 0;
      |                 ^
gondola.cpp:20:19: warning: unused variable 'm' [-Wunused-variable]
   20 |     long long i,j,m,stp = -1,of = 0;
      |                   ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:60:17: warning: unused variable 'j' [-Wunused-variable]
   60 |     long long i,j,ru = 0,stp = -1,fr,ba,rua = 0;
      |                 ^
gondola.cpp:60:38: warning: variable 'ba' set but not used [-Wunused-but-set-variable]
   60 |     long long i,j,ru = 0,stp = -1,fr,ba,rua = 0;
      |                                      ^~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:114:19: warning: unused variable 'm' [-Wunused-variable]
  114 |     long long i,j,m,stp = -1,of = 0,ans = 1,be,ru = 0,off = 0,cva,cdif,fva;
      |                   ^
gondola.cpp:114:55: warning: variable 'off' set but not used [-Wunused-but-set-variable]
  114 |     long long i,j,m,stp = -1,of = 0,ans = 1,be,ru = 0,off = 0,cva,cdif,fva;
      |                                                       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...