QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#20972 | #2476. Pizzo Collectors | ltunjic | WA | 3ms | 3692kb | C++11 | 2.0kb | 2022-02-23 01:58:21 | 2022-05-03 12:10:02 |
Judging History
answer
#include <bits/stdc++.h>
#define X first
#define Y second
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define siz size()
#define pri(i, poc, n, pov) for(int i = (int) poc; i < (int) n; i += (int) pov)
#define od(i, poc, n, pov) for(int i = (int) poc; i > (int) n; i -= (int) pov)
using namespace std;
const ll INF = 1e18;
const int LOG = 20;
const int OFF = (1 << LOG);
const int MOD = 1e9 + 7;
const int lx[8] = {1, -1, 0, 0, -1, 1, 1, -1};
const int ly[8] = {0, 0, 1, -1, -1, 1, -1, 1};
const int N = 1e5 + 10;
int abs(int x){
if(x < 0)
return -x;
return x;
}
ll n, p;
ll val[30], mx;
ll prec[OFF];
string s;
int findp(int x){
pri(i, 2, x + 1, 1){
int y = x;
while((y % i) == 0){
y /= i;
}
if(y != 1)
continue;
return i;
}
return 0;
}
ll rek(int x, int d, bool flag){
if(d > n) return 0;
ll ret = 0;
if(flag){
ret += n / d;
ret += rek(x, d * p, 1) * N;
prec[d] = ret;
return ret;
}
ll ret2 = 0;
bool cat = true;
bool qm = (s[x] == '?');
bool have = qm;
char imam = '-';
if(!qm)
imam = s[x];
ll y = x;
while(((y + d) % n) != x){
y = (y + d) % n;
if(qm && imam == '-' && s[y] != '?'){
imam = s[y];
}
if((s[y] != imam) && s[y] != '?'){
cat = false;
break;
}
if(s[y] != '?'){
qm = false;
} else {
have = true;
}
}
y = x;
for(int i = 0; i < p; i++){
ret2 += rek(y, d * p, 0);
y = (y + d) % n;
}
ret = val[imam - 'A'];
if(qm)
ret = mx;
ret *= prec[d];
if(cat)
return max(ret, ret2);
return ret2;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
setprecision(9);
int spec;
cin >> n >> s >> spec;
pri(i, 0, spec, 1){
char c;
ll w;
cin >> c >> w;
val[c - 'A'] = w;
mx = max(mx, w);
}
p = findp(n);
rek(0, 1, 1);
cout << rek(0, 1, 0) << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3692kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
1000220012601012
result:
wrong answer 1st lines differ - expected: '1301004', found: '1000220012601012'