QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#564485 | #9161. Naval battle | Bucketsmith | 0 | 1558ms | 139444kb | C++20 | 3.6kb | 2024-09-15 06:35:10 | 2024-09-15 06:35:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using node = tuple<int, int, int>;
const int N = 2e5 + 10;
int n, x[N], y[N], z[N];
char dir[N];
bool crashed[N];
/*
0: x
1: y
2: x + y
3: x - y
0: N
4: S
8: W
12: E
*/
int chg[256];
map<int, set<pii> > mp[16];
pii findCollide(int p) {
pii ans = {INT_MAX, 0};
if(dir[p] == 'E') {
auto it = mp[0 ^ chg['W']][x[p]].lower_bound(pii{y[p], p});
if(it != mp[0 ^ chg['W']][x[p]].end())
ans = min(ans, pii{(it->first - y[p]) / 2, it->second});
it = mp[2 ^ chg['N']][x[p] - y[p]].lower_bound(pii{x[p], p});
if(it != mp[2 ^ chg['N']][x[p] - y[p]].end())
ans = min(ans, pii{it->first - x[p], it->second});
it = mp[3 ^ chg['S']][x[p] + y[p]].lower_bound(pii{x[p], p});
if(it != mp[3 ^ chg['S']][x[p] + y[p]].begin()) {
it --;
ans = min(ans, pii{x[p] - it->first, it->second});
}
}else if(dir[p] == 'S') {
auto it = mp[1 ^ chg['N']][y[p]].lower_bound(pii{x[p], p});
if(it != mp[1 ^ chg['N']][y[p]].end())
ans = min(ans, pii{(it->first - x[p]) / 2, it->second});
it = mp[2 ^ chg['W']][x[p] - y[p]].lower_bound(pii{x[p], p});
if(it != mp[2 ^ chg['W']][x[p] - y[p]].end())
ans = min(ans, pii{it->first - x[p], it->second});
it = mp[3 ^ chg['E']][x[p] + y[p]].lower_bound(pii{x[p], p});
if(it != mp[3 ^ chg['E']][x[p] + y[p]].begin()) {
it --;
ans = min(ans, pii{x[p] - it->first, it->second});
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
chg['S'] = 4;
chg['W'] = 8;
chg['E'] = 12;
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> x[i] >> y[i] >> dir[i];
z[i] = chg[dir[i]];
mp[0 ^ z[i]][x[i]].insert({y[i], i});
mp[1 ^ z[i]][y[i]].insert({x[i], i});
mp[2 ^ z[i]][x[i] - y[i]].insert({x[i], i});
mp[3 ^ z[i]][x[i] + y[i]].insert({x[i], i});
}
priority_queue<node, vector<node>, greater<node> > q;
for(int i = 1; i <= n; i ++) {
auto [t, b] = findCollide(i);
//cout << "find " << i << " = " << t << ", " << b << endl;
if(b) q.push({t, i, b});
}
while(q.size()) {
auto [t, a, b] = q.top();
q.pop();
if(crashed[a] || crashed[b]) {
if(!crashed[a]) {
auto [t, b] = findCollide(a);
if(b) q.push({t, a, b});
}
continue;
}
vector<pii> v;
v.emplace_back(a, b);
while(q.size() && get<0>(q.top()) == t) {
auto [t, a, b] = q.top();
q.pop();
if(crashed[a] || crashed[b]) {
if(!crashed[a]) {
auto [t, b] = findCollide(a);
if(b) q.push({t, a, b});
}
continue;
}
v.emplace_back(a, b);
}
for(auto [a, b] : v) {
crashed[a] = crashed[b] = true;
for(auto i : {a, b}) {
mp[0 ^ z[i]][x[i]].erase({y[i], i});
mp[1 ^ z[i]][y[i]].erase({x[i], i});
mp[2 ^ z[i]][x[i] - y[i]].erase({x[i], i});
mp[3 ^ z[i]][x[i] + y[i]].erase({x[i], i});
}
//cout << a << " and " << b << " crashed at " << t << "\n";
}
}
for(int i = 1; i <= n; i ++)
if(!crashed[i]) cout << i << " ";
cout << "\n";
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 6
Accepted
time: 0ms
memory: 3904kb
input:
2 675333810 792019962 W 851860476 960355168 W
output:
1 2
result:
ok
Test #2:
score: 6
Accepted
time: 0ms
memory: 3604kb
input:
2 714148610 688520844 W 359519570 789553998 S
output:
1 2
result:
ok
Test #3:
score: 6
Accepted
time: 0ms
memory: 3836kb
input:
2 743286406 87591094 E 108453484 326740470 S
output:
1 2
result:
ok
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3864kb
input:
2 629499666 659260200 W 391550936 897208930 N
output:
1 2
result:
FAIL Unexpected end of file - token expected (/var/uoj_data/9161/4.ans)
Subtask #2:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 1ms
memory: 5736kb
input:
100 32 46 N 8 24 W 74 86 W 2 76 N 90 70 N 34 74 N 4 68 N 42 26 N 66 94 N 28 40 W 96 12 W 82 78 W 54 24 N 36 42 W 92 68 W 0 26 N 14 54 N 94 66 N 26 52 N 66 12 W 72 6 W 64 96 W 6 20 N 4 22 W 26 42 N 40 28 W 70 76 N 18 60 N 62 16 N 30 48 N 36 36 W 42 36 W 52 94 N 62 98 N 0 78 N 70 2 W 28 50 N 80 80 W 8...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
result:
FAIL Unexpected end of file - token expected (/var/uoj_data/9161/14.ans)
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #58:
score: 0
Wrong Answer
time: 1558ms
memory: 139444kb
input:
200000 526715640 430855204 E 731546662 226024182 S 254814720 702756124 E 227354364 730216480 S 764250602 193320242 S 150102088 807468756 E 204858572 752712272 S 635512190 322058654 E 403910248 553660596 S 257917918 4587926 S 949444340 8126504 S 907805098 49765746 S 553836306 403734538 S 40977864 617...
output:
9710 78188 79720
result:
FAIL Unexpected end of file - token expected (/var/uoj_data/9161/58.ans)
Subtask #7:
score: 0
Skipped
Dependency #1:
0%