답안 #259686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259686 2020-08-08T09:48:08 Z errorgorn Secret Permutation (RMI19_permutation) C++14
0 / 100
1 ms 256 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
		
		int v1,v2;
		
		v={lo,x,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);
		
		if (v2<v1){
			lo=x;
			continue;	
		}
		
		v={hi,x,lo};
		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);
		
		if (v2<v1){
			hi=x;
			continue;	
		}
	}
	
	//cout<<lo<<" "<<hi<<endl;
	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;
	//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 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 1 ms 256 KB Partially correct
4 Partially correct 1 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Incorrect 1 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 1 ms 256 KB Partially correct
4 Partially correct 1 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Incorrect 1 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 1 ms 256 KB Partially correct
4 Partially correct 1 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Incorrect 1 ms 256 KB Output isn't correct