Submission #508789

#TimeUsernameProblemLanguageResultExecution timeMemory
508789aryan12Gondola (IOI14_gondola)C++17
15 / 100
13 ms664 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; int valid(int n, int inputSeq[]) { int diff = 1e8; for(int i = 1; i <= n; i++) { if(inputSeq[i] >= 1 && inputSeq[i] <= n) { int temp = inputSeq[i] - i; if(diff == 1e8 || diff == temp || diff == temp - n || diff == temp + n) { diff = temp; } else { return 0; } } } return 1; } int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int diff = 1e8, maxx = 0, pos = 0; map<int, int> mp; for(int i = 1; i <= n; i++) { mp[gondolaSeq[i]] = i; maxx = max(maxx, gondolaSeq[i]); if(gondolaSeq[i] == maxx) { pos = i; } if(gondolaSeq[i] >= 1 && gondolaSeq[i] <= n) { int temp = gondolaSeq[i] - i; if(diff == 1e8 || diff == temp || diff == temp - n || diff == temp + n) { diff = temp; } else { assert(false); } } } for(int i = 1; i <= n; i++) { int x = diff + i; if(x <= 0) { x += n; } if(x > n) { x -= n; } gondolaSeq[i] = x; } int rPos = 0; for(int i = n + 1; i <= maxx; i++) { if(!mp.count(i)) { replacementSeq[rPos++] = gondolaSeq[pos]; gondolaSeq[pos] = i; } else { replacementSeq[rPos++] = gondolaSeq[mp[i]]; gondolaSeq[mp[i]] = i; } } return rPos; } 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...