#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound
using ll = long long;
using ld = long double;
const int N = 1e5 + 7;
const ll mod = 1e9 + 7;
int n, m;
int vis[N][2];
int xs[N], ys[N];
multiset<int> mul;
int calc(int x, int y)
{
int ret = 1e9;
if (mul.empty())
return ret;
auto eval =[&](int u) -> void{
for(int i = 0 ;i < 2 ; ++ i){
if(vis[u][i]){
ret = min(ret , (u-x)*(u-x) + (i-y)*(i-y) ) ;
}
}
} ;
auto it = mul.lb(x);
if(it != mul.end())
eval(*it) ;
if(it != mul.begin())
eval(*(--it)) ;
return ret;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
char c;
cin >> c;
if (c == 'E')
{
int Min = 0;
int wx = 0, wy = 0;
for (int a = 0; a < n; ++a)
{
for (int b = 0; b < 2; ++b)
{
int w = calc(a, b);
if (w > Min)
{
Min = w;
wx = a, wy = b;
}
}
}
xs[i] = wx, ys[i] = wy;
vis[wx][wy] = 1;
mul.insert(wx);
cout << ++wx << " " << ++wy << "\n";
}
else
{
int p;
cin >> p;
--p;
mul.erase(mul.find(xs[p]));
vis[xs[p]][ys[p]] = 0;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 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 |
203 ms |
492 KB |
Output is correct |
2 |
Correct |
8 ms |
364 KB |
Output is correct |
3 |
Correct |
73 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
620 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
73 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
1048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |