제출 #70116

#제출 시각아이디문제언어결과실행 시간메모리
70116zubec곤돌라 (IOI14_gondola)C++14
100 / 100
159 ms16868 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100100; const ll MOD = 1e9+9; int a[N], b[N]; ll fact[N]; int valid(int n, int inputSeq[]){ map<int, int> mp1; map<int, int> used, used2; for (int i = 1; i <= n; i++){ a[i] = inputSeq[i-1]; if (a[i] > n){ if (++mp1[a[i]] > 1) return 0; } } a[n+1] = a[1]; int prev = 0; for (int i = 1; i <= n; i++){ if (used.find(a[i+1]) != used.end()) a[i+1] = used[a[i+1]]; if (a[i] > n) continue; if (a[i+1] > n){ if (a[i] == n){ if (used2.find(1) != used2.end()) return 0; used[a[i+1]] = 1; used2[1] = a[i+1]; a[i+1] = 1; } else { if (used2.find(a[i]+1) != used2.end()) return 0; used[a[i+1]] = a[i]+1; used2[a[i]+1] = a[i+1]; a[i+1] = a[i]+1; } } else { if (a[i] == n){ if (a[i+1] != 1) return 0; } else { if (a[i+1] != a[i] + 1) return 0; } } } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]){ vector <pair<int, int> > vec; for (int i = 1; i <= n; i++){ a[i] = gondolaSeq[i-1]; if (a[i] > n){ vec.push_back({a[i], i}); } } a[n+1] = a[1]; for (int i = 1; i <= n; i++){ if (a[i] <= n){ if (a[i] == n) a[i+1] = 1; else a[i+1] = a[i] + 1; } } for (int i = n+1; i > 1; i--){ if (a[i] <= n){ if (a[i] == 1) a[i-1] = n; else a[i-1] = a[i] - 1; } } if (a[1] > n){ for (int i = 1; i <= n; i++) a[i] = i; } int cnt = 0; int curnumb = n+1; sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++){ int cur = a[vec[i].second]; while(cur != vec[i].first){ replacementSeq[cnt++] = cur; cur = curnumb; ++curnumb; } } return cnt; } //---------------------- ll binpow(ll a, ll b){ ll res = 1; while(b){ if (b & 1){ res = (res * a) % MOD; } a = (a * a) % MOD; b>>=1; } return res; } int countReplacement(int n, int inputSeq[]){ if (valid(n, inputSeq) == 0) return 0; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * 1ll * i) % MOD; int cnt = 0; vector <pair<int, int> > vec; for (int i = 1; i <= n; i++){ a[i] = inputSeq[i-1]; if (a[i] > n){ vec.push_back({a[i], i}); ++cnt; } } a[n+1] = a[1]; for (int i = 1; i <= n; i++){ if (a[i] <= n){ if (a[i] == n) a[i+1] = 1; else a[i+1] = a[i] + 1; } } for (int i = n+1; i > 1; i--){ if (a[i] <= n){ if (a[i] == 1) a[i-1] = n; else a[i-1] = a[i] - 1; } } ll ans = 1; if (a[1] > n) ans = n; int lst = n+1; sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++){ ans = (ans * binpow(cnt-i, vec[i].first-lst)) % MOD; lst = vec[i].first+1; } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:25:9: warning: unused variable 'prev' [-Wunused-variable]
     int prev = 0;
         ^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:93:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:157:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.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...