QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#192238 | #7233. Colored path | jeffqi# | WA | 1ms | 3536kb | C++20 | 2.4kb | 2023-09-30 14:02:02 | 2023-09-30 14:02:02 |
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] = 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: 1ms
memory: 3528kb
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: -100
Wrong Answer
time: 0ms
memory: 3536kb
input:
1 1 1 2 1
output:
1 1 1
result:
wrong answer Participiant's path is not valid.