Submission #149919

# Submission time Handle Problem Language Result Execution time Memory
149919 2019-09-01T07:23:54 Z 还没编好(#3801, cauchysheep, fjzzq2002, apiad) On the Grid (FXCUP4_grid) C++17
100 / 100
149 ms 12092 KB
#include "grid.h"
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
#include <assert.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int t[SZ],N;
bool s[SZ],mk[SZ];
bool vv[SZ];
map<vector<int>,int> ms;
int qry()
{
	vector<int> gg(N);
	for(int i=0;i<N;++i) gg[t[i]]=i;
//	for(int i=0;i<N;++i)
//		cout<<t[i]<<",";
//	cout<<":"<<PutDisks(gg)-N<<"\n";
	if(ms.count(gg)) return ms[gg];
	return ms[gg]=PutDisks(gg);
}
void ens(int tt)
{
	vector<int> gg(N);
	for(int i=0;i<N;++i) gg[t[i]]=i;
	ms[gg]=tt+N;
}
std::vector<int> SortDisks(int N_) {
	srand(time(0));
	N=N_;
	for(int i=0;i<N;++i)
		t[i]=i;
	random_shuffle(t,t+N);
	vector<int> st;
	int lg=-1;
	while(1)
	{
		int g=qry()-N;
		st.pb(g); lg=g;
	//	cout<<g<<",";
		if(!g) break;
		//0..g-1 -> 1..g-1,1
		//skip sures
		vector<pii> o;
		for(int j=0;j<N;++j)
			if(t[j]<N-g&&!s[j]) o.pb(pii(t[j],j));
		if(!o.size()) break;
		int os=o.size();
		sort(o.begin(),o.end());
		for(int j=0;j+1<os;++j)
			t[o[j].se]=o[j+1].fi;
		t[o[os-1].se]=o[0].fi;
		int w=qry()-N;
		if(w<=g-1) continue;
		assert(!s[o[os-1].se]);
		if(vv[t[o[os-1].se]+w])
		{
			ms.clear(); continue;
		}
		vv[t[o[os-1].se]=t[o[os-1].se]+w]=1;
	//	cout<<"!";
	//	cout<<"RO"<<o[os-1].se<<":"<<t[o[os-1].se]<<" "<<os<<"\n";
		s[o[os-1].se]=1;
		o.clear();
		for(int j=0;j<N;++j)
			if(!s[j]) o.pb(pii(t[j],j));
		sort(o.begin(),o.end());
		for(int j=0;j<N;++j) mk[j]=0;
		for(int j=0;j<N;++j)
			if(s[j]) mk[t[j]]=1;
		for(int j=N-1;j>=0;--j)
			if(!mk[j])
			{
				assert(!o.empty());
//				cout<<j<<"!\n";
				t[o.back().se]=j,o.pop_back();
			}
		ens(lg);
	}
//	for(int j=0;j+1<st.size();++j)
//		if(st[j]<st[j+1])
//			cout<<st[j]<<"|"<<st[j+1]<<"\n";
	vector<int> r(N);
	for(int j=0;j<N;++j) r[j]=t[j]+1;
	return r;
}
#ifdef LOCAL
#define N NN
#include "grader.cpp"
#endif
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 13 ms 640 KB Output is correct
10 Correct 13 ms 896 KB Output is correct
11 Correct 16 ms 1024 KB Output is correct
12 Correct 14 ms 1024 KB Output is correct
13 Correct 14 ms 1152 KB Output is correct
14 Correct 14 ms 1152 KB Output is correct
15 Correct 15 ms 1024 KB Output is correct
16 Correct 14 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 7288 KB Output is correct
2 Correct 14 ms 1152 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 140 ms 11768 KB Output is correct
6 Correct 14 ms 1152 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 142 ms 11896 KB Output is correct
10 Correct 15 ms 1024 KB Output is correct
11 Correct 13 ms 896 KB Output is correct
12 Correct 23 ms 1920 KB Output is correct
13 Correct 16 ms 1024 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 137 ms 11892 KB Output is correct
16 Correct 115 ms 9336 KB Output is correct
17 Correct 140 ms 12024 KB Output is correct
18 Correct 149 ms 12024 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 14 ms 1152 KB Output is correct
21 Correct 143 ms 11896 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 136 ms 12092 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 14 ms 1024 KB Output is correct