QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469048#7233. Colored pathpropaneWA 0ms3628kbC++202.4kb2024-07-09 11:41:472024-07-09 11:41:47

Judging History

你现在查看的是最新测评结果

  • [2024-07-09 11:41:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3628kb
  • [2024-07-09 11:41:47]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n, k, W;
    cin >> n >> k >> W;
    vector<vector<int> > a(n, vector<int>(n));
    vector<vector<int> > c(n, vector<int>(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]--;
        }
    }
    vector<int> pos[11];
    for(int i = 1; i < 1 << k; i++){
        pos[__builtin_popcount(i)].push_back(i);
    }
    const int INF = 0x3f3f3f3f;
    for(int cnt = 1; cnt <= k; cnt++){
        for(auto x : pos[cnt]){
            if (!(x >> c[0][0] & 1)) continue;
            vector<vector<int> > dp(n, vector<int>(n, INF));
            vector<vector<pair<int, int> > > pre(n, vector<pair<int, int> >(n));
            dp[0][0] = a[0][0];
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if (i + 1 < n and (x >> c[i + 1][j] & 1)){
                        if (dp[i][j] + a[i + 1][j] < dp[i + 1][j]){
                            dp[i + 1][j] = dp[i][j] = a[i + 1][j];
                            pre[i + 1][j] = {i, j};
                        }
                    }
                    if (j + 1 < n and (x >> c[i][j + 1] & 1)){
                        if (dp[i][j] + a[i][j + 1] < dp[i][j + 1]){
                            dp[i][j + 1] = dp[i][j] + a[i][j + 1];
                            pre[i][j + 1] = {i, j};
                        }
                    }
                }
            }
            if (dp[n - 1][n - 1] <= W){
                vector<pair<int, int> > ans{{n - 1, n - 1}};
                while(ans.back() != pair{0, 0}){
                    ans.push_back(pre[ans.back().first][ans.back().second]);
                }
                reverse(ans.begin(), ans.end());
                cout << cnt << '\n';
                for(auto [x, y] : ans) cout << x + 1 << ' ' << y + 1 << ' ';
                cout << '\n';
                return 0;
            }
        }
    }
    cout << -1 << '\n';

}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

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: 3592kb

input:

1 1 1
2
1

output:

-1

result:

ok n = 1, k = 1, W = 1

Test #3:

score: 0
Accepted
time: 0ms
memory: 3508kb

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: 3628kb

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: 3556kb

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: -100
Wrong Answer
time: 0ms
memory: 3560kb

input:

3 9 4
1 1 1
1 1 1
1 1 1
1 9 3
6 3 7
6 1 7

output:

3
1 1 2 1 3 1 3 2 3 3 

result:

wrong answer Participiant's path is not valid.