QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332328 | #7877. Balanced Array | Terdy | WA | 1ms | 3820kb | C++14 | 1.3kb | 2024-02-19 14:20:13 | 2024-02-19 14:20:13 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
# define ull unsigned long long
const int N = 2e6 + 5 , base = 2333;
int n , a[N] , ans[N];
ull ha[N] , pw[N*9];
int trans(string s)
{
int res = 0;
for(int i = 0; i < s.length(); i++)
{
if('0' <= s[i] && s[i] <= '9') res = res * 62 + s[i] - '0';
if('a' <= s[i] && s[i] <= 'z') res = res * 62 + s[i] - 'a' + 10;
if('A' <= s[i] && s[i] <= 'Z') res = res * 62 + s[i] - 'A' + 10 + 26;
}
return res;
}
void Add(int x , int k)
{
ha[k] = ha[k - 1];
for(int i = 8; ~i; i--)
{
int y = x / pow(10 , i);
y %= 10;
ha[k] = ha[k] * base + y;
}
}
ull Ha(int l , int r)
{
return ha[r] - ha[l - 1] * pw[(r - l + 1) * 9];
}
bool check(int k , int l)
{
return Ha(1 , l - 2 * k) + Ha(2 * k + 1 , l) == 2 * Ha(k + 1 , l - k);
}
int main()
{
cin >> n;
pw[0] = 1;
for(int i = 1; i <= 9 * n; i++) pw[i] = pw[i - 1] * base;
for(int i = 1; i <= n; i++)
{
string s;
cin >> s;
a[i] = trans(s);
Add(a[i] , i);
}
for(int i = 1 , j = 1; i <= (n - 1) / 2 && j <= n; i++)
{
while(i > (j - 1) / 2) j++;
while(check(i , j)) ans[j] = 1 , j++;
}
for(int i = 1; i <= n; i++) cout << ans[i];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010111
result:
ok single line: '001010111'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3776kb
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:
0000100010000000000000000000000000110000000000001
result:
wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0000100010000000000000000000000000110000000000001'