Submission #508804

#TimeUsernameProblemLanguageResultExecution timeMemory
508804aryan12Gondola (IOI14_gondola)C++17
60 / 100
28 ms5188 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; int valid(int n, int inputSeq[]) { int newSeq[n + 1]; for(int i = 1; i <= n; i++) { newSeq[i] = inputSeq[i - 1]; } for(int i = 0; i < n; i++) { if(inputSeq[i] >= 1 && inputSeq[i] <= n) { newSeq[inputSeq[i]] = inputSeq[i]; int pos = i; for(int j = inputSeq[i] + 1; j <= n; j++) { pos++; if(pos == n) { pos = 0; } newSeq[j] = inputSeq[pos]; } for(int j = 1; j <= inputSeq[i] - 1; j++) { pos++; if(pos == n) { pos = 0; } newSeq[j] = inputSeq[pos]; } break; } } map<int, int> mp; for(int i = 1; i <= n; i++) { if(mp.count(newSeq[i])) { return 0; } mp[newSeq[i]] = 1; if(newSeq[i] >= 1 && newSeq[i] <= n && newSeq[i] != i) { return 0; } } return 1; } int replacement(int n, int inputSeq[], int replacementSeq[]) { int newSeq[n + 1]; for(int i = 1; i <= n; i++) { newSeq[i] = inputSeq[i - 1]; } for(int i = 0; i < n; i++) { if(inputSeq[i] >= 1 && inputSeq[i] <= n) { newSeq[inputSeq[i]] = inputSeq[i]; int pos = i; for(int j = inputSeq[i] + 1; j <= n; j++) { pos++; if(pos == n) { pos = 0; } newSeq[j] = inputSeq[pos]; } for(int j = 1; j <= inputSeq[i] - 1; j++) { pos++; if(pos == n) { pos = 0; } newSeq[j] = inputSeq[pos]; } break; } } int maxvalue = 0, pos = 0, anspos = 0; map<int, int> op; for(int i = 1; i <= n; i++) { op[newSeq[i]] = i; maxvalue = max(maxvalue, newSeq[i]); if(newSeq[i] == maxvalue) { pos = i; } newSeq[i] = i; } for(int i = n + 1; i <= maxvalue; i++) { if(op.count(i)) { replacementSeq[anspos++] = newSeq[op[i]]; newSeq[op[i]] = i; } else { replacementSeq[anspos++] = newSeq[pos]; newSeq[pos] = i; } } return anspos; } const long long MOD = 1e9 + 9; int countReplacement(int n, int inputSeq[]) { long long diff = 1e8, maxx = 0; map<long long, long long> mp; long long NotinBetween = n; for(long long i = 1; i <= n; i++) { mp[inputSeq[i]] = i; maxx = max(maxx, (long long)inputSeq[i]); if(inputSeq[i] >= 1 && inputSeq[i] <= n) { NotinBetween--; long long temp = inputSeq[i] - i; if(diff == 1e8 || diff == temp || diff == temp - n || diff == temp + n) { diff = temp; } else { return 0; } } } long long ans = 1; for(long long i = n + 1; i <= maxx; i++) { if(mp.count(i)) { NotinBetween--; } else { ans *= NotinBetween; ans %= MOD; } } return (int)(ans); }
#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...