QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#843204 | #9970. Looping RPS | ucup-team6275# | WA | 1ms | 3848kb | C++23 | 2.5kb | 2025-01-04 17:18:59 | 2025-01-04 17:18:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for (int i = 0; i < (n); i += 1)
#define len(a) ((int)(a).size())
mt19937 rnd(234);
const int inf = 1e8;
struct SGT {
int n;
vector<pair<int, int>> t;
void build(vector<int> a) {
n = 1;
while (n < len(a)) {
n *= 2;
}
t.resize(2 * n);
rep(i, len(a)) {
t[i + n] = {a[i], i};
}
for (int i = n - 1; i >= 0; i -= 1) {
t[i] = min(t[i + i], t[i + i + 1]);
}
}
pair<int, int> get(int l, int r) {
l += n;
r += n + 1;
pair<int, int> rs = {inf + 1, -1};
while (l < r) {
if (l & 1) {
rs = min(rs, t[l]);
++l;
}
if (r & 1) {
--r;
rs = min(rs, t[r]);
}
l /= 2;
r /= 2;
}
return rs;
}
};
int n;
vector<string> a;
vector<int> d;
SGT sgt;
bool cmp(const string &a, const string &b) {
rep(i, max(len(a), len(b)) * 2) {
if (a[i % len(a)] != b[i % len(b)]) {
return (a[i % len(a)] < b[i % len(b)]);
}
}
return false;
}
ll solve(ll l, ll r) {
if (r - l + 1 < 3) {
return 0;
}
auto [mn, pos] = sgt.get(l, r - 1);
if (r == pos + 1) {
return solve(l, pos);
}
auto [mn2, pos2] = sgt.get(pos + 1, r - 1);
if (mn != mn2) {
ll res1 = solve(l, pos);
ll res2 = solve(pos + 1, r);
return res1 + res2;
}
ll myres = ll(pos - l + 1) * (pos2 - pos) * (r - pos2);
ll res1 = solve(l, pos);
ll res2 = solve(pos + 1, pos2);
ll res3 = solve(pos2 + 1, r);
return myres + res1 + res2 + res3;
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n;
a.resize(n);
rep(i, n) {
cin >> a[i];
}
sort(all(a), cmp);
d.resize(n - 1);
rep(i, n - 1) {
d[i] = inf;
for (int j = 0; j < max(len(a[i]), len(a[i + 1])) * 2; j += 1) {
if (a[i][j % len(a[i])] != a[i + 1][j % len(a[i + 1])]) {
d[i] = j;
break;
}
}
}
sgt.build(d);
ll result = solve(0, n - 1);
cout << result << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
6 P PN KK N PKK PN
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
10 KKKNP KNKPPKNK KNKPP KNKPPKN KKKN NNKNNNKNNNKNNNKNNNKNNNKNNNKNNPN NNKN NPPN NNKNNNKNNNKNNNKNNNKNNNKNNNK KKKNN
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
10 NNNPNNNPNNNPNNNK KKN NNNP KKP NNNPNNNPNNNPN KKNKKNKKPN KNNPNPNKKKNPPKNKKKNKNKKNKPPPNKKPKP KKPK KKNKKNK KKPKKN
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
10 K PPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNP PPKP PPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPNNPPPK P K N P PPPNN N
output:
25
result:
ok 1 number(s): "25"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 NPNKP NNNNKNNNNPP PPKPNNNNPNKKKN NPNKPNP NNNNKN NNNNK NKNPKKPNPKKNPNKN NKNPKKPNPKKNPNK NKNPKKPNPKKNP NPNKPNPN
output:
30
result:
ok 1 number(s): "30"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
10 KPKKPKKPKKPKKP KPKKPKKPKKPKKPKNK PNPNP KPK PN NPNPNNPNPNK NKKPKKPKPPKKPKKKKPKNKPPKPPNKNP NPNPNNP PNPNPK NPNPN
output:
39
result:
ok 1 number(s): "39"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
4 KKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPK NN KKP KKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKPKKNK
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
7 KPKN KPKNKPKNKPKNKPKK NKPPNNNPKKNN KPPKPKPPKPKPPKPKPPKPKPP KPKNKPKNKPKNKP KPPKP KPPKPKPPKPKPPKPKPPKPKPPKPN
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
10 NKNNKNKN KPKN PKPN PNNNNNNKKNNPNNKNPPKPPNPNPPKKKPNNNPNPKKNK PKPNPKP PKPNPK KPKNKP NKNNKNKNNKNPN KPKNKPK NKNNK
output:
39
result:
ok 1 number(s): "39"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
300 NKNPNK NKKNKK KPPNPN KKPNKNK PKKNPKP KPKPPPN NNKPPNN NPKPPKN KNNKKPK PPPNPKK NKPKNP KPKNNPP NNPKNP PNPPPKN PKKPNP PPNNKK PKNKNK PKNPNK NKNPNPP KNKNNPN NKPPPPK NNPPKKN KNKKNPK KKNNPKN PPPKNK NPPPPPP NKKPKPP KNKNPPK KPKPNNK NPNNKN PNPNKP PNPKKP KKKKPKN NNNKNPK NPNKPNK NNNKNK PPKKNKP NNNKPPK KPNKPP...
output:
1102940
result:
ok 1 number(s): "1102940"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
91 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKN KKKKKKKKP PNPKPPNP KKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKP KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKP KKKKKKKKKKKKKKKKKKKKKKN KKKKKKKN KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKP KKKKKKKKKKKKP ...
output:
2151
result:
ok 1 number(s): "2151"
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
72 PKPPKPPKPPKPPKPPN PKP NNNNNK NPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNPNNP NNPNNPNNPNNPNNPNNK NP PPPPPPN PKPPKPPKPPKPPKPP PPPPKPP PPK NNNNNPP NNNNPNNNNPNNNNPN KPNNNKKPPKPKKNPPKKNNKPKPKPKPPPKPPKPNNKPPKPPPNNNKKNNPKKKKKN...
output:
14796
result:
wrong answer 1st numbers differ - expected: '14794', found: '14796'