#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
pair<int, int> pos[100001];
set<pair<int, int>> active;
inline ll sq(int x) { return ll(x) * ll(x); }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int cnt = 1; cnt <= m; cnt++) {
char c;
cin >> c;
if (c == 'E') {
if (!active.size()) pos[cnt] = {1, 1};
else {
pair<ll, pair<int, int>> best = {-1, {0, 0}};
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 3; j++) {
ll dist = LLONG_MAX;
for (pair<int, int> k : active) {
dist = min(dist, sq(k.first - i) + sq(k.second - j));
}
if (dist > best.first) best = {dist, {i, j}};
}
}
pos[cnt] = best.second;
}
active.insert(pos[cnt]);
cout << pos[cnt].first << ' ' << pos[cnt].second << '\n';
} else {
int i;
cin >> i;
active.erase(pos[i]);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |