#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
double dist[150002][3];
bool occ[150002][3];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
map<int,pair<int,int> > pass;
pair<int,int> mnat = {1,1};
for(int ev = 1; ev <= m; ev++) {
char ch;
cin >> ch;
if(ch == 'E') {
int r,c;
pass[ev] = mnat;
cout << mnat.first << " " << mnat.second << "\n";
occ[mnat.first][mnat.second] = true;
} else {
int x;
cin >> x;
auto pr = pass[x];
occ[pr.first][pr.second] = false;
pass.erase(x);
}
for(int i = 1; i <= n; i++) {
dist[i][1] = dist[i][2] = 3000000;
}
for(int c = 1; c <= 2; c++) {
int lastwasat = -1;
for(int i = 1; i <= n; i++) {
if(occ[i][c]) {
lastwasat = i;
}
if(lastwasat != -1) {
dist[i][c] = min(dist[i][c],double(i-lastwasat));
}
}
lastwasat = -1;
for(int i = n; i >= 1; i--) {
if(occ[i][c]) {
lastwasat = i;
}
if(lastwasat != -1) {
dist[i][c] = min(dist[i][c],double(lastwasat-i));
}
}
}
for(int c = 1; c <= 2; c++) {
int lastwasat = -1;
for(int i = 1; i <= n; i++) {
if(occ[i][3-c]) {
lastwasat = i;
}
if(lastwasat != -1) {
dist[i][c] = min(dist[i][c],sqrt((i-lastwasat)*(i-lastwasat)+1));
}
}
lastwasat = -1;
for(int i = n; i >= 1; i--) {
if(occ[i][3-c]) {
lastwasat = i;
}
if(lastwasat != -1) {
dist[i][c] = min(dist[i][c],sqrt((i-lastwasat)*(i-lastwasat)+1));
}
}
}
mnat = {1,1};
//cout << setprecision(7);
for(int i = 1; i <= n; i++) {
for(int c = 1; c <= 2; c++) {
// cout << dist[i][c] << " ";
if(dist[i][c] > dist[mnat.first][mnat.second]+0.000001) {
mnat = {i,c};
}
}
//cout << endl;
}
//cout << endl;
//cout << endl;
}
return 0;
}
Compilation message
tram.cpp: In function 'int main()':
tram.cpp:25:8: warning: unused variable 'r' [-Wunused-variable]
25 | int r,c;
| ^
tram.cpp:25:10: warning: unused variable 'c' [-Wunused-variable]
25 | int r,c;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
620 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
82 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
480 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
73 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1036 ms |
4500 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
4332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
1048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
4460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |