Submission #363544

#TimeUsernameProblemLanguageResultExecution timeMemory
363544silverfishGondola (IOI14_gondola)C++14
25 / 100
51 ms4844 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; #define ar array #define pb push_back int valid(int n, int a[]){ bool ok = 1, first = 1; int diff = -1; map<int, int> cnt; for(int i = 0; i < n; ++i){ if(cnt[a[i]]) ok = 0; ++cnt[a[i]]; if(a[i] <= n){ if(first) { diff = (a[i]-(i+1)+n)%n; first = 0; continue; } //cerr << i+1 << ' ' << (n+a[i]-diff)%n << endl; if(i != (a[i]-diff-1+n)%n) ok = 0; } } return ok; } //---------------------- int replacement(int n, int a[], int r[]){ bool ok = 1, first = 1; int diff = -1; vector<ar<int,2>> replaced; for(int i = 0; i < n; ++i){ if(a[i] <= n){ diff = (a[i]-(i+1)+n)%n; }else{ replaced.pb({a[i], i}); } } if(diff == -1) diff = 0; sort(replaced.begin(), replaced.end()); int cur = 0, curnum = n+1; for(auto x : replaced){ int val = x[0], pos = x[1]; int orig = (pos+1 + diff + n) % n; r[cur++] = orig; for(; curnum < x[0]; ++curnum) r[cur++] = curnum; } return cur; } //---------------------- int countReplacement(int n, int a[]){ if(!valid(n, a)) return 0; return -1; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:48:7: warning: unused variable 'val' [-Wunused-variable]
   48 |   int val = x[0], pos = x[1];
      |       ^~~
gondola.cpp:32:7: warning: unused variable 'ok' [-Wunused-variable]
   32 |  bool ok = 1, first = 1;
      |       ^~
gondola.cpp:32:15: warning: unused variable 'first' [-Wunused-variable]
   32 |  bool ok = 1, first = 1;
      |               ^~~~~
#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...