답안 #259700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259700 2020-08-08T10:16:26 Z errorgorn Secret Permutation (RMI19_permutation) C++14
35 / 100
60 ms 504 KB
#include "permutation.h"

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
 
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
 
int val[100005];

void solve(int n) {
	vector<int> v;	
	int lo=1,hi=2;
	
	rep(x,3,n+1){
		//lets try to see if x is lowest or highest
		//cout<<lo<<" "<<hi<<endl;
		
		int v1,v2,v3,v4;
		
		v={x,lo,hi};
		rep(y,1,n+1) if (y!=lo && y!=x && y!=hi) v.push_back(y);
		
		v1=query(v);
		swap(v[0],v[1]);
		v2=query(v);
		
		v={x,hi,lo};
		rep(y,1,n+1) if (y!=lo && y!=x && y!=hi) v.push_back(y);
		
		v3=query(v);
		swap(v[0],v[1]);
		v4=query(v);
		
		if (v1<v2 && v3<v4){
			if (v2-v1<v4-v3) hi=x;
			else lo=x;	
		}
		else if (v1<v2) lo=x;
		else if (v3<v4) hi=x;
	}
	
	val[lo]=-1e9;
	val[hi]=1e9;
	
	rep(x,1,n+1) if (x!=lo && x!=hi){
		v={lo,hi,x};
		rep(y,1,n+1) if (y!=lo && y!=x && y!=hi) v.push_back(y);
		
		int v1,v2;
		v1=query(v);
		swap(v[0],v[1]);
		v2=query(v);
		
		val[x]=v2-v1;
	}
	
	vector<int> perm,ans(n);
	
	rep(x,1,n+1) perm.push_back(x);
	
	sort(all(perm),[](int i,int j){
		return val[i]<val[j];
	});
	
	rep(x,0,n) ans[perm[x]-1]=x+1;
	
	//for (auto &it:perm) cout<<it<<" "; cout<<endl;
	if (query(perm)!=n-1) exit(1);
	
	//for (auto &it:ans) cout<<it<<" "; cout<<endl;
	answer(ans);
}

Compilation message

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(stdin, "%d", &x);
   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(stdin, "%d", &N);
   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 260 KB Partially correct
2 Partially correct 0 ms 384 KB Partially correct
3 Partially correct 1 ms 384 KB Partially correct
4 Partially correct 2 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 1 ms 256 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 260 KB Partially correct
2 Partially correct 0 ms 384 KB Partially correct
3 Partially correct 1 ms 384 KB Partially correct
4 Partially correct 2 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 1 ms 256 KB Partially correct
7 Partially correct 5 ms 256 KB Partially correct
8 Partially correct 6 ms 256 KB Partially correct
9 Partially correct 5 ms 384 KB Partially correct
10 Partially correct 5 ms 384 KB Partially correct
11 Partially correct 3 ms 256 KB Partially correct
12 Partially correct 4 ms 256 KB Partially correct
13 Partially correct 4 ms 384 KB Partially correct
14 Partially correct 6 ms 256 KB Partially correct
15 Partially correct 4 ms 384 KB Partially correct
16 Partially correct 4 ms 384 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 260 KB Partially correct
2 Partially correct 0 ms 384 KB Partially correct
3 Partially correct 1 ms 384 KB Partially correct
4 Partially correct 2 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 1 ms 256 KB Partially correct
7 Partially correct 5 ms 256 KB Partially correct
8 Partially correct 6 ms 256 KB Partially correct
9 Partially correct 5 ms 384 KB Partially correct
10 Partially correct 5 ms 384 KB Partially correct
11 Partially correct 3 ms 256 KB Partially correct
12 Partially correct 4 ms 256 KB Partially correct
13 Partially correct 4 ms 384 KB Partially correct
14 Partially correct 6 ms 256 KB Partially correct
15 Partially correct 4 ms 384 KB Partially correct
16 Partially correct 4 ms 384 KB Partially correct
17 Partially correct 60 ms 504 KB Partially correct
18 Partially correct 50 ms 384 KB Partially correct
19 Partially correct 48 ms 384 KB Partially correct
20 Partially correct 47 ms 376 KB Partially correct
21 Partially correct 58 ms 372 KB Partially correct
22 Partially correct 51 ms 288 KB Partially correct
23 Partially correct 52 ms 376 KB Partially correct
24 Partially correct 54 ms 504 KB Partially correct
25 Partially correct 53 ms 256 KB Partially correct
26 Partially correct 54 ms 256 KB Partially correct