Submission #1067265

#TimeUsernameProblemLanguageResultExecution timeMemory
1067265slivajanFire (BOI24_fire)C++17
13 / 100
362 ms43400 KiB
#include <bits/stdc++.h> using namespace std; typedef long long un; typedef vector<un> vuc; typedef pair<un, un> pun; #define REP(i, a, b) for (un i = (un)a; i < (un)b; i++) #define FEAC(i, a) for (auto&& i : a) #define vec vector #define ALL(x) (x).begin(), (x).end() #define DEB(x) cerr << #x << " = " << (x) << endl; int main(){ un N, M; cin >> N >> M; vec<pun> vstup; map<un, un> mapa; REP(i, 0, N){ un a, b; cin >> a >> b; vstup.push_back({a, b}); mapa[a] = 0; mapa[b] = 0; } vuc imapa; un counter = 0; FEAC(kv, mapa){ un key; tie(key, ignore) = kv; mapa[key] = counter; counter++; imapa.push_back(key); } sort(ALL(vstup)); un K = imapa.size(); vuc delky(K, 0); FEAC(kd, vstup){ un key, destination; tie(key, destination) = kd; delky[mapa[key]] = (M+destination-key) % M; } un curr = 0; REP(ign, 0, 2){ REP(i, 0, K){ curr -= (M+imapa[i] - imapa[(K+i-1)%K]) % M; curr = max(curr, delky[i]); delky[i] = curr; } } vuc visited(K, 0); un ptr = 0; un time = 1; while(not visited[ptr]){ visited[ptr] = time; if (delky[ptr] == 0) { cout << -1 << endl; return 0; } ptr = mapa[(imapa[ptr] + delky[ptr]) % M]; time++; } cout << time - visited[ptr] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...