이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pic = pair<int, char>;
using pii = pair<int, int>;
using node = tuple<int, int, int>;
const int N = 2e5 + 10;
int n, x[N], y[N], fc[N][4], nxt[8][N][4];
char d[N];
bool crash[N];
int f(char c) {
const static string s = "NSWE"s;
for(int i = 0; i < 4; i ++)
if(c == s[i]) return i;
return -1;
}
int jmpNxt(int d, int u, int p) {
return crash[u] ? nxt[d][u][p] = jmpNxt(d, nxt[d][u][p], p) : u;
}
vector<int> cv[4];
int collide(int i, int j) {
if(d[i] == d[j]) return -1;
if(x[i] == x[j]) {
if(y[i] < y[j] && d[i] == 'S' && d[j] == 'N') return (y[j] - y[i]) / 2;
if(y[i] > y[j] && d[j] == 'S' && d[i] == 'N') return (y[i] - y[j]) / 2;
return -1;
}else if(y[i] == y[j]) {
if(x[i] < x[j] && d[i] == 'E' && d[j] == 'W') return (x[j] - x[i]) / 2;
if(x[j] < x[i] && d[j] == 'E' && d[i] == 'W') return (x[i] - x[j]) / 2;
return -1;
}else if(x[i] + y[i] == x[j] + y[j]) {
if(x[i] > x[j] && d[i] == 'S' && d[j] == 'E') return x[i] - x[j];
if(x[i] > x[j] && d[i] == 'W' && d[j] == 'N') return x[i] - x[j];
if(x[j] > x[i] && d[j] == 'S' && d[i] == 'E') return x[j] - x[i];
if(x[j] > x[i] && d[j] == 'W' && d[i] == 'N') return x[j] - x[i];
return -1;
}else if(x[i] - y[i] == x[j] - y[j]) {
if(x[i] > x[j] && d[i] == 'N' && d[j] == 'E') return x[i] - x[j];
if(x[i] > x[j] && d[i] == 'W' && d[j] == 'S') return x[i] - x[j];
if(x[j] > x[i] && d[j] == 'N' && d[i] == 'E') return x[j] - x[i];
if(x[j] > x[i] && d[j] == 'W' && d[i] == 'S') return x[j] - x[i];
return -1;
}
return -1;
}
priority_queue<node, vector<node>, greater<node> > pq;
int getD[8][4];
void findCollide(int u) {
if(crash[u]) return;
int t = INT_MAX, tar = -1;
for(int i = 0; i < 8; i ++)
for(int j = 0; j < 4; j ++) {
int v = jmpNxt(i, nxt[i][u][j], j);
if(v != 0) {
int x = collide(u, v);
if(x != -1 && x < t) {
t = x;
tar = v;
}
}
}
if(t < INT_MAX) pq.emplace(t, u, tar);
}
vector<pii> mp[4][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> x[i] >> y[i] >> d[i];
cv[0].push_back(x[i]);
cv[1].push_back(y[i]);
cv[2].push_back(x[i] + y[i]);
cv[3].push_back(x[i] - y[i]);
}
for(int i = 0; i < 4; i ++) {
sort(cv[i].begin(), cv[i].end());
cv[i].erase(unique(cv[i].begin(), cv[i].end()), cv[i].end());
}
for(int i = 1; i <= n; i ++) {
fc[i][0] = lower_bound(cv[0].begin(), cv[0].end(), x[i]) - cv[0].begin();
fc[i][1] = lower_bound(cv[1].begin(), cv[1].end(), y[i]) - cv[1].begin();
fc[i][2] = lower_bound(cv[2].begin(), cv[2].end(), x[i] + y[i]) - cv[2].begin();
fc[i][3] = lower_bound(cv[3].begin(), cv[3].end(), x[i] - y[i]) - cv[3].begin();
mp[0][fc[i][0]].emplace_back(fc[i][1], i);
mp[1][fc[i][1]].emplace_back(fc[i][0], i);
mp[2][fc[i][2]].emplace_back(fc[i][0], i);
mp[3][fc[i][3]].emplace_back(fc[i][0], i);
}
for(int i = 0; i < 4; i ++)
for(int j = 0; j < cv[i].size(); j ++) {
sort(mp[i][j].begin(), mp[i][j].end());
int tmp[4] = {0};
for(auto [x, p] : mp[i][j]) {
memcpy(nxt[i][p], tmp, sizeof tmp);
tmp[f(d[p])] = p;
}
reverse(mp[i][j].begin(), mp[i][j].end());
memset(tmp, 0, sizeof tmp);
for(auto [x, p] : mp[i][j]) {
memcpy(nxt[i ^ 4][p], tmp, sizeof tmp);
tmp[f(d[p])] = p;
}
}
for(int i = 1; i <= n; i ++)
findCollide(i);
while(pq.size()) {
auto [t, u, v] = pq.top();
pq.pop();
if(crash[u] || crash[v]) {
findCollide(u);
continue;
}
vector<int> w{u};
while(pq.size() && get<0>(pq.top()) == t) {
auto [it, iu, iv] = pq.top();
pq.pop();
if(crash[iu] || crash[iv]) {
findCollide(iu);
continue;
}
w.emplace_back(iu);
}
for(int i : w) {
crash[i] = true;
}
}
for(int i = 1; i <= n; i ++)
if(!crash[i]) cout << i << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:108:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int j = 0; j < cv[i].size(); j ++) {
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |