ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197068 | #3427. C | smwtcat | 100 | 1629ms | 3568kb | C++11 | 3.3kb | 2023-11-05 12:58:58 | 2023-11-05 13:05:30 |
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int Mod = 998244353;
const int inf = 0x3f3f3f3f;
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){ return (int)(1ll * a * b % Mod); }
int n, m;
string stat[8][444];
int pt[8][444], pm[8][444];
int nt[8], nm[8];
string nstat[8];
int ok[444], ed[444], upd[444];
int need[66];
int dp[66][4111], rdp[66][4111];
int S, all_ed = 0, ans;
void getp(int s, int mask){
//cout << "getp " << s << " " << mask << ": " << rdp[s][mask] << "\n";
if(s == all_ed && mask == ((1<<(2*n)) - 1)) return ;
rep(i, m){
if((ok[i] | s) != S) continue;
int nx = s | ed[i], ny = mask | upd[i];
if((ny & need[nx - s]) != need[nx - s]) continue;
if(dp[s][mask] + 1 + rdp[nx][ny] == ans){
cout << i+1 << " ";
getp(nx, ny);
return ;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
rep(i, n){
nstat[i] = "-";
rep(j, m){
cin >> stat[i][j] >> pt[i][j] >> pm[i][j];
if(nstat[i][0] == '-'){
nt[i] = max(nt[i], pt[i][j]);
nm[i] = max(nm[i], pm[i][j]);
if(stat[i][j] != "AC")
nstat[i] = stat[i][j];
}
}
if(nstat[i] == "-") nstat[i] = "AC";
//cout << i << ": " << nstat[i] << "\n";
}
rep(i, m){
rep(j, n){
ok[i] += (pt[j][i] <= nt[j] && pm[j][i] <= nm[j] && (stat[j][i] == "AC" || stat[j][i] == nstat[j])) << j;
//cout << stat[j][i] << " " << nstat[j];
ed[i] += (stat[j][i] != "AC" && stat[j][i] == nstat[j]) << j;
//cout << ed[i] << endl;
upd[i] += (pt[j][i] == nt[j]) << j;
upd[i] += (pm[j][i] == nm[j]) << (n + j);
}
//cout << i << ": " << (bitset<4>)upd[i] << "\n";
}
rep(i, 1<<n){
rep(j, n) if((i>>j) & 1){
need[i] += (1 << j) + (1 << (n+j));
}
}
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
S = (1<<n) - 1;
rep(s, 1<<n){
rep(mask, 1<<(2*n)){
int nv = dp[s][mask];
if(nv >= inf) continue;
rep(i, m){
//cout << s << " " << mask << " " << i << " " << ed[i] << "\n";
if((ok[i] | s) != S) continue;
//cout << s << " " << mask << " " << i << "\n";
int nx = s | ed[i], ny = mask | upd[i];
if((ny & need[nx - s]) != need[nx - s]) continue;
//cout << s << " " << mask << " " << i << ": " << ok[i] << "\n";
//cout << nx << ": " << need[nx - s] << endl;
if(nv + 1 < dp[nx][ny]){
dp[nx][ny] = nv + 1;
}
}
}
}
rep(i, n) all_ed += (nstat[i] != "AC") << i;
cout << (ans = dp[all_ed][(1<<(2*n)) - 1]) << "\n";
memset(rdp, 0x3f, sizeof(rdp));
rdp[all_ed][(1<<(2*n)) - 1] = 0;
//return 0;
for(int s = S; s >= 0; --s){
for(int mask = (1<<(2*n)) - 1; mask >= 0; --mask){
rep(i, m){
if((ok[i] | s) != S) continue;
int nx = s | ed[i], ny = mask | upd[i];
if((ny & need[nx - s]) != need[nx - s]) continue;
if(rdp[nx][ny] + 1 < rdp[s][mask])
rdp[s][mask] = rdp[nx][ny] + 1;
}
}
}
getp(0, 0);
cout << "\n";
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 5ms
memory: 3448kb
input:
6 9 AC 7138 3830 AC 4896 5070 WA 5738 5131 AC 2738 3125 WA 2498 4599 AC 6786 3005 AC 2217 4104 AC 57...
output:
4 1 2 3 5
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 3448kb
input:
6 10 AC 379 85 AC 5830 2992 AC 595 2461 AC 2064 2216 AC 5830 2767 AC 4615 524 AC 5692 963 AC 192 142...
output:
4 1 2 3 4
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 6ms
memory: 3444kb
input:
6 10 AC 988 4954 ML 6 10000 AC 760 5457 AC 1429 1124 AC 1429 3892 AC 940 3560 WA 571 5343 AC 1429 30...
output:
6 1 2 4 5 6 8
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 7ms
memory: 3448kb
input:
6 10 TL 10000 1949 AC 1994 2395 WA 1994 1619 AC 757 2326 AC 575 152 AC 1134 1827 AC 1994 610 AC 1172...
output:
5 1 2 3 4 5
result:
ok 2 lines
Subtask #2:
score: 20
Accepted
Test #5:
score: 20
Accepted
time: 8ms
memory: 3452kb
input:
6 20 AC 5128 516 AC 5128 181 AC 4422 195 AC 5128 516 AC 4555 516 AC 1744 80 ML 603 10000 AC 5128 313...
output:
6 1 2 3 7 8 12
result:
ok 2 lines
Test #6:
score: 0
Accepted
time: 11ms
memory: 3448kb
input:
6 18 AC 5055 259 AC 723 61 AC 5748 2338 AC 5748 2338 AC 5748 2338 ML 5748 10000 AC 5748 692 AC 5258 ...
output:
5 2 6 8 10 12
result:
ok 2 lines
Test #7:
score: 0
Accepted
time: 11ms
memory: 3448kb
input:
6 19 AC 489 114 AC 1219 71 AC 865 92 AC 1830 99 AC 299 70 AC 1361 114 AC 1866 114 AC 1654 47 AC 822 ...
output:
5 1 5 16 9 15
result:
ok 2 lines
Test #8:
score: 0
Accepted
time: 16ms
memory: 3448kb
input:
6 20 AC 2841 1313 AC 9423 1265 AC 5338 167 AC 9423 827 AC 5149 1313 AC 5628 308 TL 10000 1313 AC 760...
output:
5 2 3 5 7 13
result:
ok 2 lines
Subtask #3:
score: 30
Accepted
Test #9:
score: 30
Accepted
time: 49ms
memory: 3480kb
input:
6 99 AC 2260 697 AC 3171 2862 AC 2336 2862 AC 9724 167 AC 4019 1372 AC 4775 346 AC 1232 1888 AC 7444...
output:
5 1 2 9 33 22
result:
ok 2 lines
Test #10:
score: 0
Accepted
time: 35ms
memory: 3472kb
input:
6 92 AC 645 2828 AC 242 3059 AC 928 3460 AC 238 3590 AC 214 3590 AC 888 1470 AC 1116 3590 AC 1116 24...
output:
5 1 90 20 52 15
result:
ok 2 lines
Test #11:
score: 0
Accepted
time: 66ms
memory: 3472kb
input:
6 98 AC 8790 3105 ML 8790 10000 AC 8790 7483 AC 8790 7483 AC 1823 3796 AC 1335 1692 AC 6491 1609 ML ...
output:
6 1 7 42 73 23 12
result:
ok 2 lines
Test #12:
score: 0
Accepted
time: 43ms
memory: 3476kb
input:
6 92 TL 10000 596 ML 1023 10000 AC 2290 325 AC 2264 1963 AC 142 1963 AC 1022 1963 AC 11 79 AC 2080 1...
output:
6 1 53 4 29 7 68
result:
ok 2 lines
Subtask #4:
score: 20
Accepted
Test #13:
score: 20
Accepted
time: 139ms
memory: 3560kb
input:
6 377 AC 2089 4478 AC 6766 6473 AC 6810 2795 AC 6810 6473 AC 1190 1497 AC 1451 6473 AC 6810 6473 AC ...
output:
4 1 3 350 288
result:
ok 2 lines
Test #14:
score: 0
Accepted
time: 241ms
memory: 3560kb
input:
6 369 AC 5027 8115 AC 2417 3003 AC 6718 8115 AC 6885 7919 AC 7295 4240 AC 950 3682 AC 1034 8115 AC 7...
output:
4 266 283 284 4
result:
ok 2 lines
Test #15:
score: 0
Accepted
time: 222ms
memory: 3552kb
input:
6 367 AC 9449 3425 AC 9449 3396 AC 1594 2896 AC 1946 610 AC 6431 3425 TL 10000 3425 AC 674 2036 TL 1...
output:
4 38 10 203 278
result:
ok 2 lines
Test #16:
score: 0
Accepted
time: 188ms
memory: 3568kb
input:
6 400 ML 1769 10000 AC 4223 5355 AC 2170 3988 AC 1497 2479 AC 4956 5355 AC 3184 4357 AC 1710 5355 AC...
output:
5 1 4 201 365 390
result:
ok 2 lines
Subtask #5:
score: 20
Accepted
Test #17:
score: 20
Accepted
time: 98ms
memory: 3556kb
input:
6 360 ML 5292 10000 RE 4116 330 AC 5292 254 AC 5292 101 AC 4304 161 AC 5292 188 AC 2140 45 AC 1179 3...
output:
4 1 2 8 28
result:
ok 2 lines
Test #18:
score: 0
Accepted
time: 142ms
memory: 3556kb
input:
6 377 AC 1188 5297 AC 135 9574 AC 19 7758 AC 1028 9574 AC 1188 6614 AC 493 2039 AC 1188 3043 AC 693 ...
output:
5 1 2 3 28 312
result:
ok 2 lines
Test #19:
score: 0
Accepted
time: 155ms
memory: 3560kb
input:
6 382 ML 989 10000 AC 1580 4016 AC 614 2486 RE 1243 4016 AC 1580 4016 AC 1580 755 AC 1540 3811 AC 36...
output:
6 1 2 5 8 27 130
result:
ok 2 lines
Test #20:
score: 0
Accepted
time: 184ms
memory: 3568kb
input:
6 397 AC 198 1257 AC 94 1783 AC 213 220 AC 54 5127 AC 225 5127 AC 225 3193 AC 225 5127 AC 62 1631 AC...
output:
6 1 2 3 8 31 120
result:
ok 2 lines
Extra Test:
score: 0
Extra Test Passed