제출 #422426

#제출 시각아이디문제언어결과실행 시간메모리
422426Andyvanh1곤돌라 (IOI14_gondola)C++14
100 / 100
28 ms3016 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; #define vt vector #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ ) typedef long long ll; typedef long double ld; typedef vt<int> vi; typedef pair<int,int> pii; int x[100005]; int valid(int n, int inputSeq[]){ int at = -1; rep(i,n)x[i] = inputSeq[i]; sort(x,x+n); for(int i = 1; i < n; i++){ if(x[i]==x[i-1])return 0; } for(int i = 0; i < n; i++){ if(inputSeq[i]>n){ inputSeq[i] = -1; }else{ at = i; } } if(at==-1)return 1; bool bol = true; for(int i = at; i < n; i++){ if(inputSeq[i]!=-1&&inputSeq[i]!=(inputSeq[at]+i-at-1)%n+1){ return 0; } } for(int i = 0; i < at; i++){ if(inputSeq[i]!=-1&&inputSeq[i]!=(inputSeq[at]-at+i+n-1)%n+1){ return 0; } } return 1; } bool taken[100005]; int cur[100005]; int matr[250010]; int replacement(int n, int gondolaSeq[], int replacementSeq[]){ int Max = 0; rep(i,n){ Max = max(Max,gondolaSeq[i]); } rep(i,Max+1){ matr[i] = -1; } int at = -1; for(int i = 0; i < n; i++){ if(gondolaSeq[i]<=n){ at = i; break; } } if(at==-1){ rep(i,n){ cur[i] = i+1; } }else{ for(int i = 0; i < n; i++){ cur[i] = (gondolaSeq[at]-at+i+n-1)%n+1; if(gondolaSeq[i] <= n)taken[i] = true; } } for(int i = 0; i < n; i++){ matr[gondolaSeq[i]] = i; } for(int j = n+1; j <= Max; j++){ if(matr[j]!=-1){ replacementSeq[j-n-1] = cur[matr[j]]; cur[matr[j]] = j; taken[matr[j]] = true; }else{ for(int i = 0; i < n; i++){ if(taken[i]==false){ replacementSeq[j-n-1] = cur[i]; cur[i] = j; break; } } } } return Max-n; } #define MOD 1000000009 ll exp(ll x, int k){ if(k==0)return 1ll; ll ans = exp(x,k/2); ans*=ans; ans%=MOD; if(k&1){ ans*=x; ans%=MOD; } return ans; } int countReplacement(int n, int inputSeq[]){ int at = -1; for(int i = 0; i < n; i++){ if(inputSeq[i]<=n){ at = i; break; } } ll cur = n; ll ans = 1; sort(inputSeq, inputSeq+n); for(int i = 0; i < n; i++){ if(inputSeq[i]<=n){ cur--; }else{ if(i==0){ ans*=exp(cur,inputSeq[i]-n-1); ans*=n; ans%=MOD; }else{ if(inputSeq[i-1]<=n){ ans*=exp(cur,inputSeq[i]-n-1); ans%=MOD; }else{ ans*=exp(cur,inputSeq[i]-inputSeq[i-1]-1); ans%=MOD; } } cur--; } } return ans; }

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

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:20:5: note: in expansion of macro 'rep'
   20 |     rep(i,n)x[i] = inputSeq[i];
      |     ^~~
gondola.cpp:33:10: warning: unused variable 'bol' [-Wunused-variable]
   33 |     bool bol = true;
      |          ^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:54:5: note: in expansion of macro 'rep'
   54 |     rep(i,n){
      |     ^~~
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:57:5: note: in expansion of macro 'rep'
   57 |     rep(i,Max+1){
      |     ^~~
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:68:9: note: in expansion of macro 'rep'
   68 |         rep(i,n){
      |         ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:9: warning: variable 'at' set but not used [-Wunused-but-set-variable]
  117 |     int at = -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...