QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116662#6320. Parallel Processing (Hard)ExplodingKonjacAC ✓2ms3520kbC++175.9kb2023-06-29 18:34:402023-06-29 18:34:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-29 18:34:43]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3520kb
  • [2023-06-29 18:34:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
};

class FastOutput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	void flush()
	{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 private:
	void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	void __write(T x)
	{
		char stk[64],*top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	~FastOutput(){ flush(); }
#endif
	FastOutput &operator <<(char x)
	{ return __putc(x),*this; }
	FastOutput &operator <<(const char *s)
	{ for(;*s;__putc(*(s++)));return *this; }
	FastOutput &operator <<(const string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	enable_if_t<is_integral<T>::value,FastOutput&> operator <<(const T &x)
	{ return __write(x),*this; }
	template<typename ...T>
	void writesp(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	void writeln(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	template<typename Iter>
	void writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	void writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	void flush()
	{ buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
#endif
 private:
	bool __eof;
	char __getc()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	void __ungetc(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf_p--;
#else
		ungetc(c,target);
#endif
	}
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	bool eof()const { return feof(target); }
#endif
	char peek() { return __getc(); }
	explicit operator bool()const { return !__eof; }
	FastInput &operator >>(char &x)
	{ while(isspace(x=__getc()));return *this; }
	template<typename T>
	enable_if_t<is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=__getc()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=__getc();
		for(x=0;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return __ungetc(ch),sym?x=-x:x,*this;
	}
	FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=__getc());
		return __ungetc(*s),*s='\0',*this;
	}
	FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		__ungetc(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	void read(T &...x)
	{ initializer_list<int>{(this->operator>>(x),0)...}; }
	template<typename Iter>
	void read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

int n,a[1005];

vector<array<int,4>> ans;
void upd(int p1,int p2,int p3,int p4)
{
	auto t=tie(a[p1],a[p2],a[p3],a[p4]);
	t=make_tuple(a[a[p1]-1],a[a[p2]-1],a[a[p3]-1],a[a[p4]-1]);
	a[1001]=1002;
}
void pushAns(int p1,int p2,int p3,int p4)
{
	ans.push_back({p1,p2,p3,p4});
	upd(p1,p2,p3,p4);
}
bool dfs(int N,int dep,int lim)
{
	if(dep>lim) return count(a+1,a+N+1,1)==N;
	vector<int> ord;
	for(int i=1;i<=N;i++) if(a[i]!=1) ord.push_back(i);
	int sz=ord.size(),_p[5]={-1};
	ord.push_back(0);
	auto deal=[&](int p1,int p2,int p3,int p4)
	{
		auto old=make_tuple(a[p1],a[p2],a[p3],a[p4]);
		pushAns(p1,p2,p3,p4);
		if(dfs(N,dep+1,lim)) return true;
		ans.pop_back();
		tie(a[p1],a[p2],a[p3],a[p4])=old;
		return false;
	};
#define FP(x) for(int p##x=(_p[x]=_p[x-1]+1,0);p##x=ord[_p[x]],_p[x]<sz;_p[x]++)
	FP(1) FP(2) FP(3) FP(4)
		if(deal(p1,p2,p3,p4)) return true;
	FP(1) FP(2) FP(3)
		if(deal(p1,p2,p3,1001)) return true;
	FP(1) FP(2)
		if(deal(p1,p2,1001,1001)) return true;
	FP(1)
		if(deal(p1,1001,1001,1001)) return true;
#undef FP
	return false;
}
void solve(int N)
{
	constexpr array<int,4> ans11[]={
		{2,4,6,8},
		{3,4,8,10},
		{5,6,8,11},
		{7,9,10,11},
	},ans10[]={
		{2,3,4,6},
		{3,4,7,9},
		{5,6,7,10},
		{8,9,10,1001},
	};
	if(N==11) ans=vector(ans11,ans11+4);
	else if(N==10) ans=vector(ans10,ans10+4);
	else if(N<10)
	{
		iota(a+1,a+N+1,1),a[1001]=1002;
		ans.clear();
		if(!dfs(N,1,max((2*N+2)/5,__lg(N-1)+1)))
			assert(0);
	}
	else
	{
		solve(N-5);
		auto lst=ans.back();
		ans.pop_back();
		swap(*find(lst.begin(),lst.end(),N-5),lst[0]);
		pushAns(lst[0],lst[1],N-3,N-1);
		pushAns(lst[2],lst[3],N-3,N);
		pushAns(N-4,N,N-1,N-2);
	}
}

int main()
{
	qin>>n;
	solve(n);
	iota(a+1,a+n+1,1),a[1001]=1002;
	qout<<ans.size()<<'\n';
	for(auto &p: ans)
	{
		for(int i=0;i<4;i++)
			qout<<p[i]<<' '<<(a[p[i]]-1)<<' '<<p[i]<<'\n';
		upd(p[0],p[1],p[2],p[3]);
	}
	assert(count(a+1,a+n+1,1)==n);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3460kb

input:

17

output:

7
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
5 4 5
7 6 7
7 4 7
6 4 6
9 8 9
11 10 11
5 2 5
1001 1001 1001
9 7 9
12 11 12
12 9 12
8 7 8
14 13 14
16 15 16
11 9 11
10 9 10
14 12 14
17 16 17
13 12 13
17 14 17
16 14 16
15 14 15

result:

ok AC

Test #2:

score: 0
Accepted
time: 2ms
memory: 3468kb

input:

18

output:

7
2 1 2
4 3 4
6 5 6
8 7 8
3 2 3
4 2 4
7 6 7
8 6 8
8 4 8
6 4 6
10 9 10
12 11 12
7 4 7
5 4 5
10 8 10
13 12 13
13 10 13
9 8 9
15 14 15
17 16 17
12 10 12
11 10 11
15 13 15
18 17 18
14 13 14
18 15 18
17 15 17
16 15 16

result:

ok AC

Test #3:

score: 0
Accepted
time: 1ms
memory: 3472kb

input:

19

output:

8
2 1 2
3 2 3
4 3 4
5 4 5
3 1 3
4 2 4
6 5 6
8 7 8
5 3 5
6 3 6
7 6 7
9 8 9
9 6 9
8 6 8
11 10 11
13 12 13
7 3 7
1001 1001 1001
11 9 11
14 13 14
14 11 14
10 9 10
16 15 16
18 17 18
13 11 13
12 11 12
16 14 16
19 18 19
15 14 15
19 16 19
18 16 18
17 16 17

result:

ok AC

Test #4:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

20

output:

8
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
7 6 7
9 8 9
5 4 5
6 4 6
7 4 7
10 9 10
10 7 10
9 7 9
12 11 12
14 13 14
8 7 8
1001 1001 1001
12 10 12
15 14 15
15 12 15
11 10 11
17 16 17
19 18 19
14 12 14
13 12 13
17 15 17
20 19 20
16 15 16
20 17 20
19 17 19
18 17 18

result:

ok AC

Test #5:

score: 0
Accepted
time: 1ms
memory: 3416kb

input:

21

output:

8
2 1 2
4 3 4
6 5 6
8 7 8
3 2 3
4 2 4
8 6 8
10 9 10
5 4 5
6 4 6
8 4 8
11 10 11
11 8 11
9 8 9
13 12 13
15 14 15
10 8 10
7 6 7
13 11 13
16 15 16
16 13 16
12 11 12
18 17 18
20 19 20
15 13 15
14 13 14
18 16 18
21 20 21
17 16 17
21 18 21
20 18 20
19 18 19

result:

ok AC

Test #6:

score: 0
Accepted
time: 1ms
memory: 3404kb

input:

120

output:

48
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
7 6 7
9 8 9
5 4 5
6 4 6
7 4 7
10 9 10
10 7 10
9 7 9
12 11 12
14 13 14
8 7 8
1001 1001 1001
12 10 12
15 14 15
15 12 15
11 10 11
17 16 17
19 18 19
14 12 14
13 12 13
17 15 17
20 19 20
20 17 20
16 15 16
22 21 22
24 23 24
19 17 19
18 17 18
22 20 22
25 24 25
25 22 25...

result:

ok AC

Test #7:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

421

output:

168
2 1 2
4 3 4
6 5 6
8 7 8
3 2 3
4 2 4
8 6 8
10 9 10
5 4 5
6 4 6
8 4 8
11 10 11
11 8 11
9 8 9
13 12 13
15 14 15
10 8 10
7 6 7
13 11 13
16 15 16
16 13 16
12 11 12
18 17 18
20 19 20
15 13 15
14 13 14
18 16 18
21 20 21
21 18 21
17 16 17
23 22 23
25 24 25
20 18 20
19 18 19
23 21 23
26 25 26
26 23 26
22...

result:

ok AC

Test #8:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

464

output:

186
2 1 2
3 2 3
4 3 4
5 4 5
3 1 3
4 2 4
6 5 6
8 7 8
5 3 5
6 3 6
7 6 7
9 8 9
9 6 9
8 6 8
11 10 11
13 12 13
7 3 7
1001 1001 1001
11 9 11
14 13 14
14 11 14
10 9 10
16 15 16
18 17 18
13 11 13
12 11 12
16 14 16
19 18 19
19 16 19
15 14 15
21 20 21
23 22 23
18 16 18
17 16 17
21 19 21
24 23 24
24 21 24
20 1...

result:

ok AC

Test #9:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

812

output:

325
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
5 4 5
7 6 7
7 4 7
6 4 6
9 8 9
11 10 11
5 2 5
1001 1001 1001
9 7 9
12 11 12
12 9 12
8 7 8
14 13 14
16 15 16
11 9 11
10 9 10
14 12 14
17 16 17
17 14 17
13 12 13
19 18 19
21 20 21
16 14 16
15 14 15
19 17 19
22 21 22
22 19 22
18 17 18
24 23 24
26 25 26
21 19 21
20...

result:

ok AC

Test #10:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

862

output:

345
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
5 4 5
7 6 7
7 4 7
6 4 6
9 8 9
11 10 11
5 2 5
1001 1001 1001
9 7 9
12 11 12
12 9 12
8 7 8
14 13 14
16 15 16
11 9 11
10 9 10
14 12 14
17 16 17
17 14 17
13 12 13
19 18 19
21 20 21
16 14 16
15 14 15
19 17 19
22 21 22
22 19 22
18 17 18
24 23 24
26 25 26
21 19 21
20...

result:

ok AC

Test #11:

score: 0
Accepted
time: 1ms
memory: 3432kb

input:

996

output:

398
2 1 2
4 3 4
6 5 6
8 7 8
3 2 3
4 2 4
8 6 8
10 9 10
5 4 5
6 4 6
8 4 8
11 10 11
11 8 11
9 8 9
13 12 13
15 14 15
10 8 10
7 6 7
13 11 13
16 15 16
16 13 16
12 11 12
18 17 18
20 19 20
15 13 15
14 13 14
18 16 18
21 20 21
21 18 21
17 16 17
23 22 23
25 24 25
20 18 20
19 18 19
23 21 23
26 25 26
26 23 26
22...

result:

ok AC

Test #12:

score: 0
Accepted
time: 1ms
memory: 3452kb

input:

997

output:

399
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
5 4 5
7 6 7
7 4 7
6 4 6
9 8 9
11 10 11
5 2 5
1001 1001 1001
9 7 9
12 11 12
12 9 12
8 7 8
14 13 14
16 15 16
11 9 11
10 9 10
14 12 14
17 16 17
17 14 17
13 12 13
19 18 19
21 20 21
16 14 16
15 14 15
19 17 19
22 21 22
22 19 22
18 17 18
24 23 24
26 25 26
21 19 21
20...

result:

ok AC

Test #13:

score: 0
Accepted
time: 2ms
memory: 3496kb

input:

998

output:

399
2 1 2
4 3 4
6 5 6
8 7 8
3 2 3
4 2 4
7 6 7
8 6 8
8 4 8
6 4 6
10 9 10
12 11 12
7 4 7
5 4 5
10 8 10
13 12 13
13 10 13
9 8 9
15 14 15
17 16 17
12 10 12
11 10 11
15 13 15
18 17 18
18 15 18
14 13 14
20 19 20
22 21 22
17 15 17
16 15 16
20 18 20
23 22 23
23 20 23
19 18 19
25 24 25
27 26 27
22 20 22
21 2...

result:

ok AC

Test #14:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

999

output:

400
2 1 2
3 2 3
4 3 4
5 4 5
3 1 3
4 2 4
6 5 6
8 7 8
5 3 5
6 3 6
7 6 7
9 8 9
9 6 9
8 6 8
11 10 11
13 12 13
7 3 7
1001 1001 1001
11 9 11
14 13 14
14 11 14
10 9 10
16 15 16
18 17 18
13 11 13
12 11 12
16 14 16
19 18 19
19 16 19
15 14 15
21 20 21
23 22 23
18 16 18
17 16 17
21 19 21
24 23 24
24 21 24
20 1...

result:

ok AC

Test #15:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

1000

output:

400
2 1 2
3 2 3
4 3 4
6 5 6
3 1 3
4 2 4
7 6 7
9 8 9
5 4 5
6 4 6
7 4 7
10 9 10
10 7 10
9 7 9
12 11 12
14 13 14
8 7 8
1001 1001 1001
12 10 12
15 14 15
15 12 15
11 10 11
17 16 17
19 18 19
14 12 14
13 12 13
17 15 17
20 19 20
20 17 20
16 15 16
22 21 22
24 23 24
19 17 19
18 17 18
22 20 22
25 24 25
25 22 2...

result:

ok AC