QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#570985#9319. Bull FarmGepiWangWA 0ms3868kbC++142.3kb2024-09-17 19:36:032024-09-17 19:36:03

Judging History

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

  • [2024-09-17 19:36:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-09-17 19:36:03]
  • 提交

answer

#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Function to decode the encoded numbers
vector<int> decode(const string &encoded) {
    vector<int> decoded;
    for (size_t i = 0; i < encoded.size(); i += 2) {
        int num = (encoded[i] - 48) * 50 + (encoded[i + 1] - 48);
        decoded.push_back(num);
    }
    return decoded;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    
    while (t--) {
        int n, l, q;
        cin >> n >> l >> q;
        
        vector<vector<int>> moves(l, vector<int>(n));
        
        // Reading the movement transformations
        for (int i = 0; i < l; ++i) {
            string encoded_moves;
            cin >> encoded_moves;
            vector<int> decoded_moves = decode(encoded_moves);
            for (int j = 0; j < n; ++j) {
                moves[i][j] = decoded_moves[j] - 1;  // 0-based indexing
            }
        }
        
        string result = "";
        
        // Processing each query
        for (int i = 0; i < q; ++i) {
            string encoded_query;
            cin >> encoded_query;
            vector<int> decoded_query = decode(encoded_query);
            int a = decoded_query[0] - 1;  // Convert to 0-based
            int b = decoded_query[1] - 1;  // Convert to 0-based
            int c = decoded_query[2];      // Number of buttons used
            
            vector<int> current_pos(n);
            for (int j = 0; j < n; ++j) {
                current_pos[j] = j;  // Initial positions: 0 to n-1
            }
            
            // Apply the first `c` button presses
            for (int press = 0; press < c; ++press) {
                vector<int> new_pos(n);
                for (int j = 0; j < n; ++j) {
                    new_pos[j] = current_pos[moves[press][j]];
                }
                current_pos = new_pos;
            }
            
            // Check if the `b`-th stall is empty after the `c` button presses
            if (current_pos[a] == b) {
                result += '1';
            } else {
                result += '0';
            }
        }
        
        // Output the result for this test case
        cout << result << '\n';
    }

    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3868kb

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1001
0010

result:

wrong answer 1st lines differ - expected: '1011', found: '1001'