답안 #297245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297245 2020-09-11T12:19:01 Z miss_robot 곤돌라 (IOI14_gondola) C++14
100 / 100
79 ms 6008 KB
#include <bits/stdc++.h>
#include "gondola.h"

#pragma GCC optimize("O3")
#define ll long long
const ll M = 1e9+9;

using namespace std;

int valid(int n, int inputSeq[]){
	set<int> seen;
	for(int i = 0; i < n; i++){
		if(seen.count(inputSeq[i])) return 0;
		seen.insert(inputSeq[i]);
	}
	int pos = -1, st;
	for(int i = 0; i < n; i++) if(inputSeq[i] <= n) pos = i, st = inputSeq[i];
	if(pos == -1) return 1;
	for(int j = 0; j < n; j++, pos++, pos %= n){
		if(inputSeq[pos] > n) continue;
		if(inputSeq[pos] != (st+j-1)%n+1) return 0;
	}
	return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	int l = 0, last = n, pos = -1, st;
	vector< pair<int, int> > q;
	vector<int> p(n);
	for(int i = 0; i < n; i++) if(gondolaSeq[i] <= n) pos = i, st = gondolaSeq[i];
	if(pos == -1) for(int i = 0; i < n; i++) p[i] = i+1;
	else for(int i = 0; i < n; i++, pos++, pos %= n) p[pos] = (st+i-1)%n+1;
	for(int i = 0; i < n; i++) if(gondolaSeq[i] > n) q.push_back({gondolaSeq[i], i});
	if(q.empty()) return 0;
	sort(q.begin(), q.end());
	for(auto &t : q){
		replacementSeq[l++] = p[t.second];
		last++;
		while(last != t.first) replacementSeq[l++] = last++;
	}
	return l;
}

ll pw(ll x, ll y){
	if(!y) return 1;
	ll t = pw(x, y/2);
	t = (t*t)%M;
	if(y%2) t = (t*x)%M;
	return t;
}

int countReplacement(int n, int inputSeq[]){
	if(!valid(n, inputSeq)) return 0;
	ll s = 1, m = n;
	vector<int> a;
	for(int i = 0; i < n; i++) if(inputSeq[i] > n) a.push_back(inputSeq[i]);
	a.push_back(n);
	sort(a.begin(), a.end());
	for(int i = 0; i < (int)a.size()-1; i++){
		s *= pw(a.size()-i-1, a[i+1]-a[i]-1);
		s %= M;
	}
	for(int i = 0; i < n; i++) if(inputSeq[i] <= n) m = 1;
	s *= m, s %= M;
	return s;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:16:16: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |  int pos = -1, st;
      |                ^~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:27:33: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |  int l = 0, last = n, pos = -1, st;
      |                                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 15 ms 2176 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 32 ms 3960 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 39 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 15 ms 2176 KB Output is correct
7 Correct 15 ms 640 KB Output is correct
8 Correct 34 ms 3912 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 36 ms 4608 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 23 ms 2176 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 52 ms 4732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 11 ms 1024 KB Output is correct
12 Correct 13 ms 1024 KB Output is correct
13 Correct 18 ms 1288 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 25 ms 2360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 52 ms 4088 KB Output is correct
10 Correct 41 ms 3456 KB Output is correct
11 Correct 14 ms 1536 KB Output is correct
12 Correct 18 ms 1664 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 51 ms 4088 KB Output is correct
10 Correct 44 ms 3548 KB Output is correct
11 Correct 14 ms 1408 KB Output is correct
12 Correct 18 ms 1664 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 66 ms 4600 KB Output is correct
15 Correct 79 ms 6008 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 47 ms 4216 KB Output is correct
18 Correct 25 ms 2560 KB Output is correct