QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#323984 | #8230. Submissions | ucup-team266# | WA | 45ms | 22052kb | C++14 | 5.7kb | 2024-02-10 15:00:10 | 2024-02-10 15:00:11 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 147744151;
const int inv[5] = {0, 1, (Mod+1) / 2, (Mod+1) / 3};
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 111;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
inline void chmin(ll &a, ll b){ (b<a) ? (a=b) : 0; }
map<string, int> mp;
int cn = 0;
int has0[100100][26], fst0[100100][26], lst0[100100][26], has1[100100][26], cnt[100100], tpen[100100][26], pen[100100], can[100100];
int nhas0[100100][26], nhas1[100100][26], ntpen[100100][26];
int m;
int ord[100100];
int calc(){
rep(i, cn) ord[i] = i;
//rep(i, cn) cout << "(" << cnt[i] << " " << pen[i] << ") ";
//cout << "\n";
sort(ord, ord + cn, [&](int lh, int rh){
if(cnt[lh] != cnt[rh])
return cnt[lh] > cnt[rh];
else
return pen[lh] < pen[rh];
});
int lmt = 0;
while(lmt < cn && cnt[ord[lmt]]) ++lmt;
lmt = min((lmt+9) / 10, 35);
rep(i, lmt) can[ord[i]] = 1;
if(lmt){
int p = lmt;
while(p < cn && cnt[ord[p]] == cnt[ord[p-1]] && pen[ord[p]] == pen[ord[p-1]]) can[ord[p++]] = 1;
}
return lmt;
}
void solve(){
mp.clear(), cn = 0;
cin >> m;
rep(i, m){
memset(has0[i], 0, sizeof(has0[i])), memset(has1[i], 0, sizeof(has1[i])), can[i] = cnt[i] = pen[i] = 0;
memset(nhas0[i], 0, sizeof(nhas0[i])), memset(nhas1[i], 0, sizeof(nhas1[i]));
}
while(m--){
string c;
char cp;
int t;
string s;
cin >> c >> cp >> t >> s;
if(!mp.count(c)) mp[c] = cn++;
int id = mp[c];
int p = (int)(cp - 'A'), tp = (s[0] == 'a');
if(!has1[id][p]){
if(tp == 1){
pen[id] += (tpen[id][p] = (t + 20 * has0[id][p]));
has1[id][p] = 1;
} else {
if(!has0[id][p]) fst0[id][p] = t;
lst0[id][p] = t;
++has0[id][p];
}
} else if(!nhas1[id][p]){
if(tp == 1){
ntpen[id][p] = (t + 20 * (has0[id][p] + 1 + nhas0[id][p]));
nhas1[id][p] = 1;
} else {
++nhas0[id][p];
}
}
}
//cerr << cn << endl;
rep(i, cn) rep(j, 26) cnt[i] += has1[i][j];
int n = 0;
rep(i, cn) n += (bool)(cnt[i]);
int lmt = calc();
if(!lmt){
rep(i, cn){
int has = 0;
rep(j, 26) has |= has0[i][j];
can[i] = has;
}
} else {
int lst = ord[lmt-1];
rep(i, cn) if(!can[i]){
//cout << "! " << i << "\n";
int mnp = -1;
rep(j, 26) if(!has1[i][j] && has0[i][j] && (mnp < 0 || fst0[i][j] < fst0[i][mnp])){
mnp = j;
}
//cout << mnp << "\n";
if(mnp >= 0){
if(cnt[i] == cnt[lst]) can[i] = 1;
else {
//cout << i << ": " << (!cnt[i] && lmt < 35 && n % 10 == 0) << "\n";
int nxt = ord[lmt + (!cnt[i] && lmt < 35 && n % 10 == 0) - 1];
can[i] |= (cnt[i] + 1 > cnt[nxt] || (cnt[i] + 1 == cnt[nxt] && pen[i] + fst0[i][mnp] <= pen[nxt]));
}
}
mnp = -1;
rep(j, 26) if(has1[i][j] && has0[i][j] && (mnp < 0 || fst0[i][j] - tpen[i][j] < fst0[i][mnp] - tpen[i][mnp])){
mnp = j;
}
if(mnp >= 0){
can[i] |= (cnt[i] == cnt[lmt-1] && pen[i] + fst0[i][mnp] - tpen[i][mnp] <= pen[lmt-1]);
}
}
if(lmt){
if(cnt[ord[lmt]] == cnt[ord[lmt-1]] && pen[ord[lmt]] == pen[ord[lmt-1]])
;
else {
bool done = 0;
rep(i, lmt){
int u = ord[i];
rep(j, 26) if(has1[u][j]){
if(!nhas1[u][j] && (cnt[u] - 1 < cnt[ord[lmt]] || (cnt[u] - 1 == cnt[ord[lmt]] && pen[u] - tpen[u][j] >= pen[ord[lmt]]))){
--cnt[u], pen[u] -= tpen[u][j];
calc(); done = 1;
++cnt[u], pen[u] += tpen[u][j];
} else if(cnt[u] == cnt[ord[lmt]] && pen[u] - tpen[u][j] + ntpen[u][j] >= pen[ord[lmt]]){
pen[u] += ntpen[u][j] - tpen[u][j];
calc(); done = 1;
pen[u] -= ntpen[u][j] - tpen[u][j];
}
if(done) break;
}
if(done) break;
}
if(done) calc();
}
}
rep(i, cn) if(!cnt[i]){
int mxp = -1;
rep(j, 26) if(has0[i][j]){
if(mxp < 0 || lst0[i][j] + 20 * (has0[i][j] - 1) > lst0[i][mxp] + 20 * (has0[i][mxp] - 1))
mxp = j;
}
if(mxp >= 0){
++cnt[i], pen[i] += lst0[i][mxp] + 20 * (has0[i][mxp] - 1);
calc();
break;
}
}
}
int sum = 0;
for(auto it : mp) sum += (can[it.second]);
cout << sum << "\n";
for(auto it : mp) if(can[it.second]) cout << it.first << " ";
cout << "\n";
}
int main(){
//freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T--)
solve();
//cerr << 1. * clock() / CLOCKS_PER_SEC << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 18008kb
input:
2 5 TSxingxing10 G 0 rejected TSxingxing10 B 83 accepted aoliaoligeiliao J 98 accepted TS1 J 118 accepted TS1 B 263 accepted 12 AllWayTheNorth A 0 rejected YaoYaoLingXian Y 10 accepted XuejunXinyoudui1 X 200 rejected XuejunXinyoudui1 X 200 accepted LetItRot L 215 accepted AllWayTheNorth W 250 accept...
output:
2 TS1 TSxingxing10 4 AllWayTheNorth ImYourFan LetItRot XuejunXinyoudui1
result:
ok 2 test cases ok. (2 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 15868kb
input:
2 2 jiangly_fan A 1 accepted jiangly B 23 accepted 3 conqueror_of_tourist A 1 accepted conqueror_of_tourist A 2 accepted tourist B 23 accepted
output:
2 jiangly jiangly_fan 1 conqueror_of_tourist
result:
ok 2 test cases ok. (2 test cases)
Test #3:
score: 0
Accepted
time: 0ms
memory: 20040kb
input:
2 13 A A 1 accepted A X 1 accepted K K 1 rejected B B 2 accepted C C 2 accepted D D 2 accepted E E 2 accepted F F 2 accepted G G 2 accepted H H 2 accepted I I 2 accepted J J 2 accepted K K 2 rejected 12 A A 1 accepted A X 1 accepted B B 2 accepted C C 2 accepted D D 2 accepted E E 2 accepted F F 2 a...
output:
11 A B C D E F G H I J K 1 A
result:
ok 2 test cases ok. (2 test cases)
Test #4:
score: 0
Accepted
time: 0ms
memory: 17972kb
input:
2 11 A A 1 accepted B B 1 accepted C C 2 accepted D D 2 accepted E E 2 accepted F F 2 accepted G G 2 accepted H H 2 accepted I I 2 accepted J J 2 accepted K K 2 accepted 12 A A 1 accepted A X 1 accepted K K 1 rejected B B 2 accepted C C 2 accepted D D 2 accepted E E 2 accepted F F 2 accepted G G 2 a...
output:
2 A B 2 A K
result:
ok 2 test cases ok. (2 test cases)
Test #5:
score: 0
Accepted
time: 45ms
memory: 20048kb
input:
100000 1 M3JytWoaEXxkACy_mBAQ R 111 accepted 1 sQ O 151 accepted 1 JinbrcS58gNEE5yTSkT B 140 accepted 1 cklwBY V 243 accepted 1 v_o42YmvEKFwy Q 260 rejected 1 ftQVK8S_um22w K 265 accepted 1 _bQBeFeDpYQhvZcLf9l3 Z 147 accepted 1 KvDcEAIDN A 75 rejected 1 H3MUK6 A 101 rejected 1 gxYo_oCFn2J8aIben U 54...
output:
1 M3JytWoaEXxkACy_mBAQ 1 sQ 1 JinbrcS58gNEE5yTSkT 1 cklwBY 1 v_o42YmvEKFwy 1 ftQVK8S_um22w 1 _bQBeFeDpYQhvZcLf9l3 1 KvDcEAIDN 1 H3MUK6 1 gxYo_oCFn2J8aIben 1 _isnlUGK0ddI 1 BERcVjyCp 1 6In2do_50ylch 1 f0r3SXc6brMjT 1 7njYOapSwvogA 1 x 1 y1w3KvxylfxwprRBYw 1 aGedzS 1 iPo0GDhIF 1 4Vf...
result:
ok 100000 test cases ok. (100000 test cases)
Test #6:
score: -100
Wrong Answer
time: 35ms
memory: 22052kb
input:
10000 42 Bzs0PiQMXGZ5rRZ_2D G 2 accepted 9XtB_VIfbRRL E 11 accepted FVJL M 13 rejected a S 19 accepted tsd Z 20 rejected MyCqVEg1ONjZ U 22 accepted 6SgZMn N 51 rejected Qua1Pti3vKhyQKDUm P 54 accepted i29 M 63 accepted zPqu D 68 rejected xx2yiu6x C 71 rejected fYuK1KNkuyO5HRCq L 76 rejected tXWpYVqj...
output:
4 Qua1Pti3vKhyQKDUm fYuK1KNkuyO5HRCq tsd xiLm0TUOF3T 2 JP t3 2 77sgqpbTIr_Zt1 fhYPGC8W82NwJTQL 2 3BQ pVWDEz 2 buCeoOotAkV8DaFD6 tg 1 UkXQ3iaNJ 2 ALTqPt7JUSLrl vwfw 1 QTEzV6tp 3 4e1l0pO8eFjZwkDo 9cy_y_RNRwex8j7224hz wJlbqIU 2 6mbCu5zA eiuF7a_ 1 xy6QBr8ECi 3 PezeyUurYoz7N1iGU _Yej1PrINtydmO...
result:
wrong answer the numbers are different in the case 155. (test case 155)