Cod sursa(job #3233690)

Utilizator MirceaDonciuLicentaLicenta Mircea Donciu MirceaDonciuLicenta Data 4 iunie 2024 16:53:33
Problema Atac Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <climits>

using namespace std;

struct PairHash {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};

int main() {
    int N, M, P;
    cin >> N >> M >> P;

    unordered_map<pair<int, int>, int, PairHash> bombs;

    for (int i = 0; i < M; ++i) {
        int u, v, b;
        cin >> u >> v >> b;
        bombs[{u, v}] = b;
    }

    int X, Y, A, B, C, D;
    cin >> X >> Y >> A >> B >> C >> D;

    vector<pair<int, int>> pairs;
    pairs.push_back({X, Y});

    for (int i = 1; i < M; ++i) {
        int prevX = pairs[i - 1].first;
        int prevY = pairs[i - 1].second;
        int newX = (A * prevX + B * prevY + C) % N + 1;
        int newY = (A * prevY + B * prevX + D) % N + 1;
        pairs.push_back({newX, newY});
    }

    vector<int> results;
    for (int i = M - P; i < M; ++i) {
        int u = pairs[i].first;
        int v = pairs[i].second;
        if (bombs.find({u, v}) != bombs.end()) {
            results.push_back(bombs[{u, v}]);
        } else {
            results.push_back(100001);  // Assuming maximum possible value as no bomb required
        }
    }

    for (int res : results) {
        cout << res << endl;
    }

    return 0;
}