QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#20989#2476. Pizzo CollectorsltunjicWA 4ms3740kbC++112.0kb2022-02-23 03:56:452022-05-03 12:10:58

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:58]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3740kb
  • [2022-02-23 03:56:45]
  • 提交

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

ll n, p;
ll val[30], mx; 
ll prec[OFF];
string s;

ll findp(ll x){
	if((x % 2) == 0) 
		return 2;
	pri(i, 3, x + 1, 2){ 
		if((x % i) == 0)
			return i;
	}
	return 1;
}

ll rek(int x, ll d){ 
	if(d > n || d < 1) return 0;
	
	ll ret = 0;
	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;
		}
	}

	if(p != n){
		y = x;
		for(int i = 0; i < p; i++){ 
			ret2 += rek(y, d * p);
			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);
	
	if(n == 1){
		if(s[0] == '?')
			cout << mx << "\n";
		else 
			cout << val[s[0] - 'A'] << "\n";
		return 0;
	}

	prec[n] = 1; 
	for(int i = n / p; i > 1; i /= p){ 
		prec[i] = n / i + prec[i * p] * p; 
	}
	prec[1] = n + prec[p] * p;	

	cout << rek(0, 1) << "\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
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: 3740kb

input:

4
ABCD
4
A 4
B 3
C 2
D 1

output:

10

result:

ok single line: '10'

Test #3:

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

input:

2
AB
2
A 1
B 2

output:

0

result:

wrong answer 1st lines differ - expected: '3', found: '0'