답안 #51670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51670 2018-06-19T18:54:42 Z Mamnoon_Siam 곤돌라 (IOI14_gondola) C++17
65 / 100
87 ms 7096 KB
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a,val) memset(a, val, sizeof a)
#define PB push_back
#define endl '\n'

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
    return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;
template<typename T> using min_pq =
	priority_queue<T, vector<T>, greater<T> >;

//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};


int valid(int n, int inputSeq[]) {
	if(n == 1) return 1;
	int idx = -1, id = -1;
	for(int i = 0; i < n; i++) {
		if(inputSeq[i] <= n) {
			idx = i, id = inputSeq[i];
			break;
		}
	}
	set<int> st(inputSeq, inputSeq + n);
	if(idx == -1 or st.size() != n) return int(st.size() == n);
	vector<int> v(n);
	int flag = 1;
	for(int val = id, i = idx; val != id or flag; val = val == n ? 1 : val + 1, i = (i + 1) % n) {
		v[i] = val; flag = 0;
	}
	for(int i = 0; i < n; i++) {
		if(inputSeq[i] <= n) {
			if(inputSeq[i] != v[i])
				return 0;
		}
	} return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  return -2;
}

//----------------------

const int mod = 1e9 + 9;

int qpow(int b, int p) {
	if(p < 0) return qpow(qpow(b, -p), mod - 2);
	int ret = 1; while(p) {
		if(p & 1) ret = (1LL * ret * b) % mod;
		b = (1LL * b * b) % mod, p >>= 1;
	} return ret;
}

int countReplacement(int n, int inputSeq[]) {
	if(!valid(n, inputSeq)) return 0;
	vector<int> v;
	for(int i = 0; i < n; i++) {
		if(inputSeq[i] > n)
			v.push_back(inputSeq[i]);
	}
	sort(all(v));
	int ret = 1;
	int prev = n;
	for(int i = 0; i < v.size(); i++) {
		ret = (1LL * ret * qpow(v.size() - i, v[i] - prev - 1)) % mod;
		prev = v[i];
	}
	int flag = 0;
	for(int i = 0; i < n; i++)
		if(inputSeq[i] <= n)
			flag = 1;
	if(!flag) ret = (1LL * ret * n) % mod;
	return ret;
}

Compilation message

gondola.cpp: In function 'int myrand(int, int)':
gondola.cpp:17:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
  ^~
gondola.cpp:17:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
                          ^~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:42:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(idx == -1 or st.size() != n) return int(st.size() == n);
                  ~~~~~~~~~~^~~~
gondola.cpp:42:55: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(idx == -1 or st.size() != n) return int(st.size() == n);
                                             ~~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:85:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) {
                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 536 KB Output is correct
2 Correct 3 ms 536 KB Output is correct
3 Correct 2 ms 536 KB Output is correct
4 Correct 2 ms 544 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 12 ms 2592 KB Output is correct
7 Correct 42 ms 4000 KB Output is correct
8 Correct 27 ms 4384 KB Output is correct
9 Correct 9 ms 4384 KB Output is correct
10 Correct 25 ms 5028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5028 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 2 ms 5028 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 13 ms 5028 KB Output is correct
7 Correct 51 ms 5028 KB Output is correct
8 Correct 32 ms 5028 KB Output is correct
9 Correct 8 ms 5028 KB Output is correct
10 Correct 28 ms 5100 KB Output is correct
11 Correct 2 ms 5100 KB Output is correct
12 Correct 2 ms 5100 KB Output is correct
13 Correct 23 ms 5100 KB Output is correct
14 Correct 2 ms 5100 KB Output is correct
15 Correct 65 ms 5244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5244 KB Integer -2 violates the range [0, 350000]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5244 KB Integer -2 violates the range [0, 350000]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5244 KB Integer -2 violates the range [0, 350000]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5244 KB Output is correct
2 Correct 3 ms 5244 KB Output is correct
3 Correct 2 ms 5244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5244 KB Output is correct
2 Correct 2 ms 5244 KB Output is correct
3 Correct 2 ms 5244 KB Output is correct
4 Correct 2 ms 5244 KB Output is correct
5 Correct 2 ms 5244 KB Output is correct
6 Correct 2 ms 5244 KB Output is correct
7 Correct 2 ms 5244 KB Output is correct
8 Correct 2 ms 5244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5244 KB Output is correct
2 Correct 2 ms 5244 KB Output is correct
3 Correct 3 ms 5244 KB Output is correct
4 Correct 2 ms 5244 KB Output is correct
5 Correct 2 ms 5244 KB Output is correct
6 Correct 2 ms 5244 KB Output is correct
7 Correct 2 ms 5244 KB Output is correct
8 Correct 2 ms 5244 KB Output is correct
9 Correct 52 ms 5244 KB Output is correct
10 Correct 40 ms 5244 KB Output is correct
11 Correct 15 ms 5244 KB Output is correct
12 Correct 19 ms 5244 KB Output is correct
13 Correct 5 ms 5244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5244 KB Output is correct
2 Correct 2 ms 5244 KB Output is correct
3 Correct 2 ms 5244 KB Output is correct
4 Correct 2 ms 5244 KB Output is correct
5 Correct 2 ms 5244 KB Output is correct
6 Correct 2 ms 5244 KB Output is correct
7 Correct 2 ms 5244 KB Output is correct
8 Correct 3 ms 5244 KB Output is correct
9 Correct 52 ms 5244 KB Output is correct
10 Correct 41 ms 5244 KB Output is correct
11 Correct 16 ms 5244 KB Output is correct
12 Correct 22 ms 5244 KB Output is correct
13 Correct 6 ms 5244 KB Output is correct
14 Correct 69 ms 5756 KB Output is correct
15 Correct 87 ms 7096 KB Output is correct
16 Correct 13 ms 7096 KB Output is correct
17 Correct 47 ms 7096 KB Output is correct
18 Correct 24 ms 7096 KB Output is correct