QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20973#2476. Pizzo CollectorsltunjicRE 3ms3608kbC++112.0kb2022-02-23 01:58:552022-05-03 12:10:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 12:10:05]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3608kb
  • [2022-02-23 01:58:55]
  • 提交

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) * p;

		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: 100
Accepted
time: 3ms
memory: 3608kb

input:

8
?A?B?A?C
3
A 1
B 1000
C 100000

output:

1301004

result:

ok single line: '1301004'

Test #2:

score: 0
Accepted
time: 3ms
memory: 3576kb

input:

4
ABCD
4
A 4
B 3
C 2
D 1

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 3ms
memory: 3584kb

input:

2
AB
2
A 1
B 2

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 3ms
memory: 3588kb

input:

7
???????
3
A 1
B 3
C 2

output:

42

result:

ok single line: '42'

Test #5:

score: -100
Runtime Error

input:

1
?
26
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 13
N 14
O 15
P 16
Q 17
R 18
S 19
T 20
U 21
V 22
W 23
X 24
Y 25
Z 26

output:


result: