QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460059#7877. Balanced ArrayOvO_ZuoWA 1ms5940kbC++141.5kb2024-06-30 20:42:242024-06-30 20:42:26

Judging History

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

  • [2024-06-30 20:42:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5940kb
  • [2024-06-30 20:42:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e6+5,B=12331;

int n;
int a[N];
int get_c() {
	int v=0;
	char c=getchar();
	for(;!((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9'));c=getchar());
	for(;((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9'));c=getchar()) {
		if(c>='0'&&c<='9') v=v*62+(c-'0');
		else if(c>='a'&&c<='z') v=v*62+(c-'a')+10;
		else v=v*62+(c-'A')+36;
	}
	return v;
}
ull haxi[N],b[N];
ull gv(int l,int r) { 
	if(l>r) return 0ull;
	return haxi[r]-haxi[l-1]*b[r-l+1];
}	
bool check(int len,int r) {
	return gv(1,r-2*len)+gv(2*len+1,r)==
			2*gv(len+1,r-len);
}
int main() {
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++) a[i]=get_c();
	
	b[0]=1;
	for(i=1;i<=n;i++) b[i]=b[i-1]*B;
	for(i=1;i<=n;i++) haxi[i]=haxi[i-1]*B+a[i];
	
	int ps=0,mn=-1;
	for(i=1;2*i+1<=n;i++) {	
		for(;ps<=n&&check(i,ps+1);++ps) {
			if(ps+1<2*i+1) printf("0");
			else printf("1");
		}
	}
	puts("");
	return 0;
}
/*
给定序列 a,问其有多少个前缀满足存在 k 满足 a[i]+a[i+2*k]=2*a[i+k]
对于一个 k ,满足条件的是一段前缀,k 合法的是一段后缀
即满足限制的是一段区间,且随着 k 增大,区间的左端点单调递增
即若 j<k 且 j 的右端点 >= k 的右端点,k 毫无作用
从小到达枚举 k,维护当前最大的右端点,每次尝试右移右端点
太精妙了,直接维护哈希值可以 O(1) 判断区间是否合法
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5896kb

input:

3
1 2 3

output:

001

result:

ok single line: '001'

Test #2:

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

input:

9
1 2 3 2 5 4 3 8 5

output:

001010111

result:

ok single line: '001010111'

Test #3:

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

input:

9
1C 3f 4S 3h 88 6x 4W d1 8c

output:

001010111

result:

ok single line: '001010111'

Test #4:

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

input:

49
71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke

output:

0000111111001000000000001000000000110000100000001

result:

ok single line: '0000111111001000000000001000000000110000100000001'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5940kb

input:

48
4LZe2 4LZt4 4LZI6 4LZX8 4LZtY 4LZe2 4LZtX 4LZe2 4LYYd 4LYZ2 4LYZy 4LZe2 4LZtG 4LZtT 4LZe2 4LYtm 6g6ce 4LZe2 4LYYI 8MRDV 4LZu3 6tLzK 4WUft 7EU0p 5FVal 4LZe2 4LZe2 4LZu8 4LZe2 4LXtE 7KcGm 4LYXX 4LYYn 5v3aX 4LZtC 4LZu3 4LZe2 4LYYI 4LZtQ 4TSBp 4LYYB 4LZe2 4MatY 4LYYi 57PgU axOxK 6zQCA 4LZe2

output:

00110000000000110000000000001110000000000000111

result:

wrong answer 1st lines differ - expected: '001100000000001100000000000011100000000000001110', found: '00110000000000110000000000001110000000000000111'