QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#461485#403. Memory2PCCdayo100 ✓11ms3992kbC++143.2kb2024-07-02 19:33:012024-07-02 19:33:02

Judging History

你现在查看的是最新测评结果

  • [2024-07-02 19:33:02]
  • 评测
  • 测评结果:100
  • 用时:11ms
  • 内存:3992kb
  • [2024-07-02 19:33:01]
  • 提交

answer

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


#define pii pair<int,int>
#define fs first
#define sc second

const int mxn = 110;
int N;
pii pre[mxn],nxt[mxn];
int cnt[mxn];
bitset<mxn> alive;

void del(int p){
	alive[p] = false;
	int tl = pre[p].fs,tr = nxt[p].fs;
	nxt[tl] = pii(tr,Flip(tl,tr));
	pre[tr] = pii(tl,nxt[tl].sc);
}

void solve(){
	memset(cnt,0,sizeof(cnt));
	int rt = 0;
	for(rt = 0;rt<N*2&&!alive[rt];rt++);
	assert(rt<N*2);
	int len = alive.count();
	int now = rt;
	cerr<<"SOLVE: ";

	do{
		cnt[nxt[now].sc]++;
		now = nxt[now].fs;
		cerr<<now<<"-"<<nxt[now].sc<<"->";
	}while(now != rt);

	cerr<<endl;

	if(len == 2){
		cerr<<"LEN = 2"<<endl;
		int mx = max_element(cnt,cnt+mxn)-cnt;
		Answer(now,nxt[now].fs,mx);
		return;
	}
	else if(len == 4){
		cerr<<"LEN = 4"<<endl;
		do{
			int tmp = nxt[now].sc;
			cerr<<now<<' '<<nxt[now].fs<<":"<<tmp<<"::"<<cnt[tmp]<<endl;
			if(cnt[tmp] == 1){
				Answer(now,nxt[now].fs,tmp);
				now = nxt[nxt[now].fs].fs;
				Answer(now,nxt[now].fs,nxt[now].sc);
				return;
			}
			now = nxt[now].fs;
		}while(now != rt);
		cerr<<"SYMMETRIC"<<endl;
		int other = nxt[nxt[now].fs].fs;
		Answer(now,other,Flip(now,other));
		now = nxt[now].fs,other = nxt[other].fs;
		Answer(now,other,Flip(now,other));
		return;
	}

	int mx = *max_element(cnt,cnt+mxn);
	cerr<<"MX:" <<mx<<endl;

	if(mx == 4){
		cerr<<"FOUR"<<endl;
		vector<int> v;
		for(int tar = 0;tar<N;tar++){
			if(cnt[tar] != 4)continue;
			while(pre[now].sc == tar)now = nxt[now].fs;
			rt = now;
			do{
				if(pre[now].sc != tar&&nxt[now].sc == tar)v.push_back(nxt[now].fs);
				else if(pre[now].sc == tar&&nxt[now].sc != tar)v.push_back(pre[now].fs);
				now = nxt[now].fs;
			}while(now != rt);
			sort(v.begin(),v.end());v.resize(unique(v.begin(),v.end())-v.begin());
			cerr<<"V:";for(auto &i:v)cerr<<i<<',';cerr<<endl;
			if(v.size() != 2)exit(0);
			assert(v.size() == 2);
			Answer(v[0],v[1],tar);
			del(v[0]);
			del(v[1]);
			solve();
			return;
		}
	}
	else{
		assert(mx == 3);
		for(int tar = 0;tar<N;tar++){
			if(cnt[tar] != 3)continue;
			deque<int> dq;
			do{
				pii t1 = nxt[now];
				pii t2 = nxt[t1.fs];
				pii t3 = nxt[t2.fs];
				if(t1.sc != tar||t2.sc != tar||t3.sc != tar){
					now = nxt[now].fs;
					continue;
				}
				dq = {now,t1.fs,t2.fs,t3.fs};
				break;
			}while(now != rt);
			if(dq.empty())continue;
			cerr<<"DQ: ";for(auto &i:dq)cerr<<i<<',';cerr<<endl;
			assert(dq.size() == 4);
			if(Flip(dq[0],dq[3]) != tar){
				Answer(dq[1],dq[2],tar);
				del(dq[1]);
				del(dq[2]);
				solve();
				return;
			}
			else if(Flip(dq[0],dq[2]) != tar){
				Answer(dq[1],dq[3],tar);
				del(dq[1]);
				del(dq[3]);
				solve();
				return;
			}
			else{
				Answer(dq[0],dq[2],tar);
				del(dq[0]);
				del(dq[2]);
				solve();
				return;
			}
		}
		assert(false);
	}

	assert(false);
	return;
}

void Solve(int T, int NN){
	N = NN;
	for(int i = 0;i<N*2;i++)alive[i] = true;
	for(int i = 1;i<N*2;i++){
		pre[i] = pii(i-1,Flip(i-1,i));
		nxt[i-1] = pii(i,pre[i].sc);
	}
	pre[0] = pii(N*2-1,Flip(0,N*2-1));
	nxt[N*2-1] = pii(0,pre[0].sc);
	cerr<<"IN SOLVE"<<endl;
	solve();
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3804kb

Test #2:

score: 10
Accepted
time: 11ms
memory: 3920kb

Test #3:

score: 10
Accepted
time: 0ms
memory: 3660kb

Test #4:

score: 10
Accepted
time: 0ms
memory: 3772kb

Test #5:

score: 10
Accepted
time: 3ms
memory: 3776kb

Test #6:

score: 10
Accepted
time: 0ms
memory: 3684kb

Test #7:

score: 10
Accepted
time: 7ms
memory: 3732kb

Test #8:

score: 10
Accepted
time: 3ms
memory: 3800kb

Subtask #2:

score: 50
Accepted

Test #9:

score: 50
Accepted
time: 0ms
memory: 3668kb

Test #10:

score: 50
Accepted
time: 4ms
memory: 3736kb

Test #11:

score: 50
Accepted
time: 3ms
memory: 3660kb

Test #12:

score: 50
Accepted
time: 11ms
memory: 3880kb

Test #13:

score: 50
Accepted
time: 0ms
memory: 3924kb

Test #14:

score: 50
Accepted
time: 0ms
memory: 3740kb

Test #15:

score: 50
Accepted
time: 0ms
memory: 3792kb

Test #16:

score: 50
Accepted
time: 0ms
memory: 3792kb

Test #17:

score: 50
Accepted
time: 0ms
memory: 3976kb

Test #18:

score: 50
Accepted
time: 0ms
memory: 3992kb

Subtask #3:

score: 40
Accepted

Test #19:

score: 40
Accepted
time: 3ms
memory: 3784kb

Test #20:

score: 40
Accepted
time: 4ms
memory: 3920kb

Test #21:

score: 40
Accepted
time: 3ms
memory: 3744kb

Test #22:

score: 40
Accepted
time: 3ms
memory: 3768kb

Test #23:

score: 40
Accepted
time: 0ms
memory: 3696kb

Test #24:

score: 40
Accepted
time: 0ms
memory: 3976kb

Test #25:

score: 40
Accepted
time: 9ms
memory: 3776kb

Test #26:

score: 40
Accepted
time: 0ms
memory: 3856kb

Test #27:

score: 40
Accepted
time: 0ms
memory: 3772kb

Test #28:

score: 40
Accepted
time: 3ms
memory: 3992kb

Extra Test:

score: 0
Extra Test Passed