QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#192248 | #7233. Colored path | jeffqi# | TL | 1000ms | 6812kb | C++20 | 2.4kb | 2023-09-30 14:03:16 | 2023-09-30 14:03:17 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;
namespace qiqi {
void main() {
int n,m,V;
cin >> n >> m >> V;
vector<vi> a(n,vi(n)),c(n,vi(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> c[i][j]; c[i][j]--;
}
}
const int inf = 1e9;
int ans = m+1,sa = 0;
vector<vi> vis,f;
vector<vector<pii>> pre;
auto chk = [&](int s) {
vis.assign(n,vi(n,0));
f.assign(n,vi(n,inf));
pre.assign(n,vector<pii>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((s >> c[i][j])&1) {
vis[i][j] = 1;
}
}
}
if (vis[0][0]) {
f[0][0] = a[0][0];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i+1 < n && vis[i+1][j] && f[i+1][j] > f[i][j]+a[i+1][j]) {
f[i+1][j] = f[i][j]+a[i+1][j];
pre[i+1][j] = pair(i,j);
}
if (j+1 < n && vis[i][j+1] && f[i][j+1] > f[i][j]+a[i][j+1]) {
f[i][j+1] = f[i][j]+a[i][j+1];
pre[i][j+1] = pair(i,j);
}
}
}
return f[n-1][n-1] <= V;
};
for (int s = 1; s < (1<<m); s++) {
if (chk(s)) {
int k = __builtin_popcount(s);
if (k < ans) {
ans = k; sa = s;
}
}
}
if (!sa) {
cout << -1 << '\n';
}
else {
cout << ans << '\n';
chk(sa);
vector<pii> va({});
int x = n-1,y = n-1;
va.eb(x,y);
while (x != 0 || y != 0) {
tie(x,y) = pre[x][y];
va.eb(x,y);
}
reverse(all(va));
for (auto [px,py]:va) {
cout << px+1 << ' ' << py+1 << ' ';
}
}
}
}
int main() {
// clock_t st = clock();
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
qiqi::main();
}
// cout << (double)(clock()-st)/CLOCKS_PER_SEC;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
3 3 10 1 1 1 5 3 1 5 3 1 1 2 3 2 2 1 3 3 2
output:
2 1 1 1 2 2 2 2 3 3 3
result:
ok n = 3, k = 3, W = 10
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 1 1 2 1
output:
-1
result:
ok n = 1, k = 1, W = 1
Test #3:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 6 1000 10 10 1 10 1 1 2 1
output:
1 1 1 1 2 2 2
result:
ok n = 2, k = 6, W = 1000
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 1 1 1 1
output:
1 1 1
result:
ok n = 1, k = 1, W = 1
Test #5:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 5 5 3 6 4 8 5 9 8 9 8 2 2 2 3 5 1 5 4 5
output:
-1
result:
ok n = 3, k = 5, W = 5
Test #6:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
3 9 4 1 1 1 1 1 1 1 1 1 1 9 3 6 3 7 6 1 7
output:
-1
result:
ok n = 3, k = 9, W = 4
Test #7:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
3 10 52 5 1 1 6 10 1 1 8 1 5 1 1 7 10 6 9 4 2
output:
4 1 1 1 2 1 3 2 3 3 3
result:
ok n = 3, k = 10, W = 52
Test #8:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
2 1 1 3 2 1 2 1 1 1 1
output:
-1
result:
ok n = 2, k = 1, W = 1
Test #9:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 9 577242701 2 8 4 93069 100700 8 103515 71104 86459 6 5 6 3 7 6 1 3 5
output:
2 1 1 1 2 1 3 2 3 3 3
result:
ok n = 3, k = 9, W = 577242701
Test #10:
score: 0
Accepted
time: 1000ms
memory: 6812kb
input:
392 9 769077345 6 738409 549905 686694 654367 645778 579048 739427 649079 613869 754858 335007 420208 493900 523765 262885 438569 671847 689600 554166 767092 351644 779228 780891 730798 479799 550524 668660 350341 783080 615532 414923 706681 313717 606283 400552 785638 732092 645631 643460 622895 66...
output:
7 1 1 2 1 3 1 3 2 3 3 3 4 4 4 4 5 5 5 6 5 7 5 7 6 7 7 7 8 8 8 9 8 9 9 9 10 9 11 9 12 9 13 10 13 10 14 11 14 11 15 11 16 12 16 12 17 12 18 13 18 14 18 14 19 14 20 14 21 14 22 15 22 15 23 16 23 17 23 17 24 18 24 18 25 19 25 20 25 21 25 22 25 22 26 23 26 24 26 25 26 26 26 26 27 26 28 26 29 27 29 28 29 ...
result:
ok n = 392, k = 9, W = 769077345
Test #11:
score: 0
Accepted
time: 9ms
memory: 6776kb
input:
385 1 246860241 1 283293 312335 424037 419288 401174 427898 303232 412240 366902 345517 413407 426524 326470 147823 317597 421621 427818 419206 316486 334562 301081 408652 407405 404134 248412 421173 397119 362978 377182 367313 162006 177803 150834 283962 257395 403227 348910 428097 368952 268027 41...
output:
1 1 1 2 1 3 1 4 1 4 2 4 3 4 4 5 4 6 4 7 4 7 5 7 6 8 6 9 6 10 6 11 6 11 7 11 8 12 8 13 8 13 9 14 9 14 10 14 11 15 11 16 11 16 12 16 13 16 14 17 14 18 14 19 14 20 14 20 15 21 15 21 16 21 17 21 18 22 18 23 18 24 18 25 18 25 19 26 19 26 20 27 20 27 21 27 22 27 23 28 23 29 23 30 23 31 23 31 24 32 24 32 2...
result:
ok n = 385, k = 1, W = 246860241
Test #12:
score: 0
Accepted
time: 2ms
memory: 3856kb
input:
97 5 12056206 14150 4916 343153 408064 13844 444427 42451 48490 465541 97554 399573 193397 531104 558097 85224 197121 108772 68006 165031 303362 48786 221352 181599 168805 377792 239592 467227 542928 367101 52656 414815 81507 228158 374862 283919 227664 345124 473299 566751 384099 40824 168797 42693...
output:
-1
result:
ok n = 97, k = 5, W = 12056206
Test #13:
score: 0
Accepted
time: 67ms
memory: 4840kb
input:
203 7 56779886 520346 297254 38326 450278 488138 225867 34036 308983 317037 29141 428292 59158 81158 402430 207824 338831 491110 417978 445456 185068 465107 377141 136814 523848 467625 35661 43975 507689 421812 291421 317058 310411 399742 378964 190823 235651 161053 292885 188909 301748 104351 14067...
output:
7 1 1 2 1 2 2 2 3 3 3 4 3 5 3 6 3 6 4 7 4 7 5 8 5 8 6 9 6 9 7 9 8 10 8 10 9 10 10 11 10 11 11 12 11 13 11 13 12 14 12 15 12 16 12 16 13 16 14 17 14 17 15 18 15 19 15 19 16 19 17 20 17 20 18 21 18 22 18 23 18 23 19 23 20 23 21 23 22 24 22 25 22 25 23 25 24 25 25 26 25 27 25 28 25 29 25 29 26 30 26 31...
result:
ok n = 203, k = 7, W = 56779886
Test #14:
score: 0
Accepted
time: 5ms
memory: 4284kb
input:
205 2 38714523 327513 239486 233604 328114 151132 334977 85104 353518 217959 276826 174254 75301 30945 57443 329643 147417 100776 160376 192982 138801 382402 331863 29060 101550 112997 147837 59464 328037 174627 65206 380296 38619 225547 216733 136285 75477 140902 15546 189071 288240 145247 78570 34...
output:
-1
result:
ok n = 205, k = 2, W = 38714523
Test #15:
score: 0
Accepted
time: 8ms
memory: 4732kb
input:
222 3 226506694 2 2 37097 11359 35765 38256 40295 20557 18951 38602 32515 27515 27916 39374 33755 29299 29192 24103 22237 38124 34790 37340 40068 37710 26869 27569 35819 35073 36447 31556 30650 10783 39549 32135 32341 16980 34207 39207 36348 27408 36203 22985 39299 32271 14189 33442 39792 37914 3002...
output:
3 1 1 1 2 2 2 3 2 4 2 4 3 4 4 5 4 6 4 6 5 7 5 8 5 9 5 9 6 9 7 10 7 11 7 11 8 12 8 13 8 14 8 15 8 16 8 17 8 18 8 19 8 20 8 21 8 21 9 22 9 22 10 23 10 24 10 25 10 25 11 26 11 27 11 27 12 27 13 28 13 28 14 29 14 29 15 29 16 30 16 31 16 31 17 31 18 31 19 31 20 31 21 31 22 31 23 31 24 31 25 32 25 33 25 3...
result:
ok n = 222, k = 3, W = 226506694
Test #16:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
115 1 718900512 1 23835 19330 35303 22288 18265 36376 24242 32587 23472 18430 36247 33174 34666 27333 36121 29931 21441 22776 35367 33593 26992 32809 31663 30711 30251 18408 30326 34908 30518 26733 35274 30461 29028 34757 36084 34962 32998 35161 28650 26244 35647 29336 19503 18362 32524 24890 30146 ...
output:
1 1 1 2 1 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 4 8 4 9 5 9 5 10 5 11 5 12 5 13 6 13 7 13 7 14 7 15 8 15 9 15 10 15 11 15 12 15 13 15 14 15 14 16 15 16 15 17 15 18 16 18 16 19 17 19 18 19 18 20 19 20 19 21 19 22 19 23 20 23 21 23 21 24 21 25 22 25 23 25 23 26 23 27 23 28 24 28 24 29 25 29 25 30 26 30 27 3...
result:
ok n = 115, k = 1, W = 718900512
Test #17:
score: 0
Accepted
time: 23ms
memory: 4164kb
input:
118 7 19862909 34097 35044 781602 442856 359425 855070 744831 677425 18237 716526 110015 377175 567310 483154 866632 65306 46839 524442 439173 852856 157150 226964 226864 793865 17176 836798 623219 49756 703604 300040 39184 29543 823541 105755 725838 180136 174190 140469 402885 740285 685059 145344 ...
output:
-1
result:
ok n = 118, k = 7, W = 19862909
Test #18:
score: 0
Accepted
time: 10ms
memory: 4424kb
input:
190 4 748654630 1 1 2 2 3 1 4 704047 488172 661273 680960 461790 590683 707252 266308 640158 623653 462562 622079 618349 407360 677312 712854 429509 666245 602889 654352 646054 611298 716101 674228 697004 597254 703900 662305 715951 606309 540350 658217 666164 511600 555636 398433 692220 620873 7154...
output:
3 1 1 1 2 1 3 1 4 1 5 1 6 1 7 2 7 2 8 2 9 3 9 3 10 3 11 3 12 4 12 4 13 4 14 4 15 4 16 4 17 5 17 6 17 7 17 7 18 8 18 9 18 9 19 10 19 11 19 11 20 11 21 11 22 11 23 11 24 11 25 12 25 12 26 12 27 12 28 13 28 13 29 13 30 14 30 14 31 15 31 15 32 16 32 16 33 17 33 17 34 17 35 17 36 17 37 18 37 19 37 20 37 ...
result:
ok n = 190, k = 4, W = 748654630
Test #19:
score: 0
Accepted
time: 698ms
memory: 5684kb
input:
327 9 91174764 139898 391573 547170 9777 125523 536166 600359 593224 238444 441914 57021 572028 394926 493557 343291 402130 621029 127933 344717 47781 652065 379941 475874 500786 108776 102747 3573 472840 145423 532827 442496 487027 419026 288845 255765 585577 47932 326072 442829 557994 149576 49006...
output:
-1
result:
ok n = 327, k = 9, W = 91174764
Test #20:
score: 0
Accepted
time: 5ms
memory: 3872kb
input:
100 5 545689346 3 490934 567555 550146 511389 503585 618309 553471 537308 361754 615217 493876 548255 570391 625134 480552 245671 542381 576857 488193 424606 531449 523004 617720 622108 582083 463604 407859 539969 524466 408015 547123 484723 400785 392517 515389 401662 622700 486646 607068 614003 40...
output:
2 1 1 2 1 3 1 4 1 5 1 6 1 7 1 7 2 7 3 8 3 9 3 9 4 9 5 9 6 10 6 11 6 11 7 11 8 12 8 12 9 12 10 12 11 12 12 12 13 13 13 13 14 14 14 14 15 15 15 15 16 16 16 16 17 16 18 17 18 17 19 18 19 19 19 19 20 20 20 21 20 21 21 21 22 21 23 21 24 21 25 21 26 21 27 22 27 22 28 23 28 24 28 24 29 24 30 25 30 25 31 26...
result:
ok n = 100, k = 5, W = 545689346
Test #21:
score: -100
Time Limit Exceeded
input:
400 10 4253 10 848399 705451 856580 888529 762693 851071 559741 958306 556629 871624 863336 977576 721880 849683 900889 838202 497651 979528 765775 567493 794245 779805 968857 900682 658556 774191 360297 579548 971163 764057 877339 900108 863696 877384 910879 993359 989973 875363 912112 702809 94056...