#include <bits/stdc++.h>
#define REP(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#else
#define in cin
#define out cout
#endif
///brute
int n,m;
const int nmax = 150005,inf = 1000000005;
pair<int,int> queries[nmax];
int a[nmax][3];
int squared(int x) {
return x * x;
}
int find_distance(int y, int x, int i, int j) {
return squared(y - i) + squared(x - j);
}
int get_dis(int y, int x) {
int min_distance = inf;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
if (a[i][j] == 1) {
min_distance = min(min_distance,find_distance(y,x,i,j));
}
}
}
return min_distance;
}
pair<int,int> add() {
pair<int,int> sol;
int max_dis = -inf;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
if (a[i][j] == 1) continue;
int dis = get_dis(i,j);
if (dis > max_dis) {
max_dis = dis;
sol = {i,j};
}
}
}
return sol;
}
int main() {
in >> n >> m;
for (int i = 1; i <= m; i++) {
char type;
in >> type;
if (type == 'E') {
pair<int,int> pos = add();
out << pos.first << " " << pos.second << "\n";
a[pos.first][pos.second] = 1;
queries[i] = pos;
} else {
int pos;
in >> pos;
a[queries[pos].first][queries[pos].second] = 0;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1093 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |