Submission #373477

#TimeUsernameProblemLanguageResultExecution timeMemory
373477idk321Gondola (IOI14_gondola)C++11
100 / 100
72 ms6124 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 250005; const int mod = 1000000009; int valid(int n, int seq[]) { set<int> vis; for (int i = 0; i < n; i++) { if (vis.find(seq[i]) != vis.end()) return 0; vis.insert(seq[i]); } int cur = -1; for (int i = 0; i < n; i++) seq[i]--; for (int i = 0; i < n; i++) { if (seq[i] < n) { cur = i; break; } } if (cur == -1) return 1; int val = seq[cur]; for (int i = cur + 1; i < n; i++) { val++; val %= n; if (seq[i] < n && seq[i] != val) return 0; } return 1; } //---------------------- int replacement(int n, int seq[], int seq2[]) { vector<int> to(M, -1); int biggest = -1; int cbig = -1; for (int i = 0; i < n; i++) { seq[i]--; to[seq[i]] = i; if (seq[i] > cbig) { cbig = seq[i]; biggest = i; } } if (cbig == n - 1) return 0; int org[M]; for (int i = 0; i < n; i++) org[i] = -1; for (int i = 0; i < n; i++) { if (seq[i] < n) { for (int j = 0; j < n; j++) { org[j] = ((seq[i] - (i - j)) % n + n) % n; } break; } } if (org[0] == -1) { for (int i = 0; i < n; i++) org[i] = i; } int cur = 0; for (int cnum = n; cnum <= cbig; cnum++) { if (to[cnum] == -1) { seq2[cur] = org[biggest] + 1; org[biggest] = cnum; } else { seq2[cur] = org[to[cnum]] + 1; org[to[cnum]] = cnum; } cur++; } return cur++; } /* 4 2 10 11 */ //---------------------- int expo(int num, int p) { ll cur = num; ll res = 1; while (p > 0) { if (p % 2 == 0) { p /= 2; cur *= cur; cur %= mod; } else { res *= cur; res %= mod; p--; } } return res; } int countReplacement(int n, int seq[]) { if (!valid(n, seq)) return 0; vector<int> big; int open = 0; for (int i = 0; i < n; i++) { if (seq[i] >= n) { open++; big.push_back(seq[i]); } } bool allBigger = true; for (int i = 0; i < n; i++) if (seq[i] < n) allBigger = false; long long res = 1; if (allBigger) res = n; big.push_back(n - 1); sort(big.begin(), big.end()); for (int i = 1; i < big.size(); i++) { int dist = big[i] - big[i - 1] - 1; res *= expo(open, dist); res %= mod; open--; } return res; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:171:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |     for (int i = 1; i < big.size(); i++)
      |                     ~~^~~~~~~~~~~~
#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...