-
Notifications
You must be signed in to change notification settings - Fork 0
/
stuckinarut.cpp
53 lines (49 loc) · 1.26 KB
/
stuckinarut.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <tuple>
using namespace std;
int main() {
int N; cin >> N;
int cows[N][5];
for (int i=0; i<N; i++) {
char direction; cin >> direction;
if (direction == 'E') {
cows[i][0] = 0;
} else {
cows[i][0] = 1;
}
cin >> cows[i][1] >> cows[i][2];
cows[i][3] = 0;
cows[i][4] = 1;
}
int field[700][700] = {};
for (int time = 0; time < 600; time++) {
for (int i=0; i<N; i++) {
if (cows[i][4] != 0) {
if (field[cows[i][1]][cows[i][2]] != 0 && field[cows[i][1]][cows[i][2]] != time) {
cows[i][4] = 0;
} else {
cows[i][3]++;
field[cows[i][1]][cows[i][2]] = time;
if (cows[i][0] == 0) {
cows[i][1]++;
} else {
cows[i][2]++;
}
}
}
}
}
for (int i=0; i<N; i++) {
if (cows[i][4] != 0) {
cout << "Infinity" << endl;
} else {
cout << cows[i][3] << endl;
}
}
}