QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441562#8176. Next TTPC 3HKOI0#WA 3ms10496kbC++142.3kb2024-06-14 16:13:492024-06-14 16:13:50

Judging History

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

  • [2024-06-14 16:13:50]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:10496kb
  • [2024-06-14 16:13:49]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define all(a) begin(a), end(a)
using namespace std;

const int N = 1e6 + 11;
const int INF = 1LL << 60;
bool v[2][N];
int P[2] = {}, g;
string TTPC = "TTPC";

string s[4];
int ps[N * 2], id[N], comp[N];

void precalc(){
	g = __gcd(P[0], P[1]);
	for (int r = 0; r < g; r++) {
		for (int x = r, i = 0; x != r || i == 0; x = (x + P[0]) % P[1], i++) {
			id[x] = i; ps[x] = i == 0 ? v[1][x] : ps[(x + P[1] - P[0]) % P[1]] + v[1][x];
			comp[r] = ps[x];
		}
	}
	// for (int x = 0; x < P[1]; x++) {
	// 	cout << v[1][x] << ' ';
	// }
	// cout << '\n';
	// for (int x = 0; x < P[1]; x++) {
	// 	cout << id[x] << ' ';
	// }
	// cout << '\n';
	// for (int x = 0; x < P[1]; x++) {
	// 	cout << ps[x] << ' ';
	// }
	// cout << '\n';
	// for (int x = 0; x < g; x++) {
	// 	cout << comp[x] << ' ';
	// }
	// cout << '\n';
}

int partial(int l, int r){
	l = (l % P[1] + P[1]) % P[1];
	r = (r % P[1] + P[1]) % P[1];
	if (id[l] < id[r]) return ps[r] - ps[l];
	else return ps[r] - ps[l] + comp[l % g];
}

int calc(int k){
	int tot = 0;
	for (int r = 0; r < g; r++) {
		for (int x = r; x < P[0]; x += g) {
			int cont = 0;
			int hv = k / P[0] + (x < k % P[0]);
			if (!v[0][x]) continue;
			cont += comp[r] * (hv / (P[1] / g));
			int rm = hv % (P[1] / g);
			cont += partial(x - P[0], x + P[0] * (rm - 1));
			tot += cont;
		}
	}
	return tot;
}

void solve() {
	int N; cin >> N;
	for (int i = 0; i < 4; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < 2; i++) {
		P[i] = s[i * 2].size() * s[i * 2 + 1].size();
		for (int j = 0; j < P[i]; j++) {
			if (s[i * 2][j % s[i * 2].size()] == TTPC[i * 2]
			&&  s[i * 2 + 1][j % s[i * 2 + 1].size()] == TTPC[i * 2 + 1]) {
				v[i][j] = true;
			}
		}
	}

	// for (int i = 0; i < 2; i++) {
	// 	for (int j = 0; j < P[i]; j++) {
	// 		cout << v[i][j];
	// 	}
	// 	cout << '\n';
	// }

	if (P[0] > P[1]) {
		swap(P[0], P[1]);
		swap(v[0], v[1]);
	}
	precalc();

	int lo = 1, hi = INF;
	while (lo != hi) {
		int mid = (lo + hi) / 2;
		if (calc(mid) >= N) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	cout << (lo == INF ? -1 : lo) << '\n';
}

int32_t main(){
#ifndef LOCAL
	cin.tie(0)->sync_with_stdio(false);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 10496kb

input:

3
TTPC
TLE
P
AC

output:

34

result:

ok "34"

Test #2:

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

input:

670055
TF
OITFKONTO
GFPPNPWTZP
CCZFB

output:

-1

result:

ok "-1"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 9796kb

input:

910359
TOKYO
TECH
PROGRAMMING
CONTEST

output:

1401951301

result:

wrong answer 1st words differ - expected: '1401951321', found: '1401951301'