QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#491298#4912. WereYouLastlifan100 ✓5635ms4988kbC++14884b2024-07-25 18:36:022024-07-25 18:36:02

Judging History

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

  • [2024-07-25 18:36:02]
  • 评测
  • 测评结果:100
  • 用时:5635ms
  • 内存:4988kb
  • [2024-07-25 18:36:02]
  • 提交

answer

// 
bool query(int);
void modify(int,bool);

bool WereYouLast(int n,int m) {
	if (m == 10) {
		int pos = 0;
		for (int i = 1; i <= m; i++) {
			pos = (pos<<1)|query(i);
		}
		++pos;
		if (pos == n) return 1;
		for (int i = m; i >= 1; i--) {
			modify(i, pos&1);
			pos >>= 1;
		}
		return 0;
	}
	
	int k = 0;
	do n >>= 1;
	while (n && (++k));
	int kk = 5; 
	
	int pos = 0;
	for (int i = 1; i <= kk; i++) {
		if (query(i)) {
			pos = pos | (1 << (i-1));
		} 
	} 
	
	pos ++;
	if (pos == (1<<kk)) return 1;

	if (query(kk+pos)) {
		modify(kk+pos, 0);
		int _p = pos;
		for (int i = 1; i <= kk; i++) {
			modify(i, _p&1);
			_p >>= 1;
		}
	} else {
		if (pos == k) {
			for (int i = 1; i <= kk; i++) {
				modify(i, 1);
			}
			return 0;
		}
		modify(kk+pos, 1); 
		for (int i = 1; i <= kk; i++) {
			modify(i, 0);
		}
	} 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3740kb

input:

1024 10

output:

12345876 10 10

result:

ok Correct Answer.
C1 = 10.
C2 = 10.

Subtask #2:

score: 20
Accepted

Test #2:

score: 20
Accepted
time: 6ms
memory: 4924kb

input:

65536 100000

output:

12345876 6 6

result:

ok Correct Answer.
C1 = 6.
C2 = 6.

Subtask #3:

score: 30
Accepted

Test #3:

score: 30
Accepted
time: 85ms
memory: 4976kb

input:

1048576 100000

output:

12345876 6 6

result:

ok Correct Answer.
C1 = 6.
C2 = 6.

Subtask #4:

score: 40
Accepted

Test #4:

score: 40
Accepted
time: 5635ms
memory: 4988kb

input:

67108864 100000

output:

12345876 6 6

result:

ok Correct Answer.
C1 = 6.
C2 = 6.