QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20960#2476. Pizzo CollectorsltunjicWA 4ms3664kbC++112.0kb2022-02-21 23:05:052022-05-03 12:08:16

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:08:16]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3664kb
  • [2022-02-21 23:05:05]
  • 提交

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;
}

int n, p;
ll val[30], mx; 
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;

		int y = x;
		for(int i = 0; i < p; i++){ 
			ret += rek(y, d * p, 1);
			y = (y + d) % n;
		}

		return ret;
	}

	ll ret2 = 0;
	
	bool cat = true;
	bool qm = (s[x] == '?');

	int y = x;
	while(((y + d) % n) != x){
		y = (y + d) % n;
		if(s[y] != s[x] && s[y] != '?'){
			cat = false;
			break;
		}
		if(s[y] != '?')
			qm = false;
	}

	y = x;
	for(int i = 0; i < p; i++){ 
		ret2 += rek(y, d * p, 0);
		y = (y + d) % n;
	}

	ret = val[s[x] - 'A'];
	if(qm)
		ret = mx;
	ll m = rek(x, d, 1);
	ret *= m; 

	//cout << x << " " << d << " "<< flag << " " << cat << " " << qm << " " << ret << " " << ret2 << "\n"; 

	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);
	
	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: 0ms
memory: 3576kb

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: 4ms
memory: 3608kb

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: 3616kb

input:

2
AB
2
A 1
B 2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

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

output:

42

result:

ok single line: '42'

Test #5:

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

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:

26

result:

ok single line: '26'

Test #6:

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

input:

4
A?A?
2
A 10
B 25

output:

140

result:

ok single line: '140'

Test #7:

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

input:

1
?
26
A 925691
B 784415
C 459872
D 532761
E 723841
F 43610
G 550337
H 362598
I 433441
J 830094
K 706780
L 870926
M 169396
N 614810
O 151788
P 802159
Q 74805
R 357984
S 654014
T 738826
U 367213
V 361083
W 22154
X 662187
Y 120341
Z 932546

output:

932546

result:

ok single line: '932546'

Test #8:

score: -100
Wrong Answer
time: 3ms
memory: 3632kb

input:

8
AB??BBBC
3
A 226880
B 21007
C 187937

output:

994619

result:

wrong answer 1st lines differ - expected: '1331550', found: '994619'