# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
801560 |
2023-08-02T06:37:00 Z |
이성호(#10091) |
IOI 바이러스 (JOI21_fever) |
C++17 |
|
27 ms |
37936 KB |
#include <iostream>
#include <cassert>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <functional>
#define all(v) (v).begin(), (v).end()
using namespace std;
struct Dot
{
int x, y;
Dot operator-(Dot d)
{
return {x - d.x, y - d.y};
}
};
int N;
Dot dot[100005];
int dir[100005];
bool infect[100005];
int dis[100005];
Dot mv[4];
/*
int coll(int i, int j)
{
if (dir[i] == dir[j]) return -1;
Dot del = dot[j] - dot[i], ver = mv[dir[i]] - mv[dir[j]];
if (ver.x < 0) {
ver.x *= -1; del.x *= -1;
}
if (ver.y < 0) {
ver.y *= -1; del.y *= -1;
}
if (del.x < 0 || del.y < 0) return -1;
if (ver.y == 0) {
if (del.y) return -1;
return del.x * 2 / ver.x;
}
if (ver.x == 0) {
if (del.x) return -1;
return del.y * 2 / ver.y;
}
return del.y / ver.y == del.x / ver.x ? (2 * del.y / ver.y) : -1;
*/
const int inf = 1e9;
set<pair<int, int>> diag[2][100005][4];
int diagid[100005][2];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("sample-05-in.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
mv[0] = {1, 0};
mv[1] = {0, 1};
mv[2] = {-1, 0};
mv[3] = {0, -1};
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> dot[i].x >> dot[i].y;
if (i >= 2) {
dot[i].x -= dot[1].x;
dot[i].y -= dot[1].y;
}
}
dot[1] = {0, 0};
int ans = 0;
for (int k = 0; k < 4; k++) {
for (int i = 2; i <= N; i++) {
int tmp = dot[i].y;
dot[i].y = dot[i].x;
dot[i].x = -tmp;
}
dir[1] = 0;
for (int i = 2; i <= N; i++) {
if (dot[i].y < dot[i].x && -dot[i].x < dot[i].y) {
dir[i] = 2;
}
else if (dot[i].y >= dot[i].x && dot[i].y > -dot[i].x) {
dir[i] = 3;
}
else if (dot[i].y < dot[i].x && dot[i].y <= -dot[i].x) {
dir[i] = 1;
}
else if (dot[i].y >= dot[i].x && dot[i].y <= -dot[i].x) {
dir[i] = 0;
}
else {
assert(0);
}
}
vector<int> cpx1, cpx2;
for (int i = 1; i <= N; i++) {
cpx1.push_back(dot[i].y - dot[i].x);
cpx2.push_back(dot[i].x + dot[i].y);
}
sort(all(cpx1));
sort(all(cpx2));
cpx1.erase(unique(all(cpx1)), cpx1.end());
cpx2.erase(unique(all(cpx2)), cpx2.end());
auto lb = [&](vector<int> &vc, int v)
{
return lower_bound(all(vc), v) - vc.begin();
};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < 4; k++) {
diag[i][j][k].clear();
}
}
}
for (int i = 1; i <= N; i++) {
diagid[i][0] = lb(cpx1, dot[i].y-dot[i].x);
diagid[i][1] = lb(cpx2, dot[i].y+dot[i].x);
diag[0][diagid[i][0]][dir[i]].insert(make_pair(dot[i].x, i));
diag[1][diagid[i][1]][dir[i]].insert(make_pair(dot[i].x, i));
}
fill(dis + 1, dis + N + 1, inf);
dis[1] = 0;
priority_queue<pair<int, int>> pq; pq.push(make_pair(0, 1));
while (!pq.empty()) {
int cur = pq.top().second, now = -pq.top().first;
pq.pop();
if (dis[cur] < now) continue;
int id0 = diagid[cur][0], id1 = diagid[cur][1];
if (dir[cur] == 0) {
int least = dot[cur].x + (now + 1) / 2;
auto it = diag[0][id0][3].lower_bound(make_pair(least, -1));
while (it != diag[0][id0][3].end()) {
int nxt = (*it).second, tm = ((*it).first - dot[cur].x) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
auto it2 = it++; diag[0][id0][3].erase(it2);
}
auto it3 = diag[1][id1][1].lower_bound(make_pair(least, -1));
while (it3 != diag[1][id1][1].end()) {
int nxt = (*it3).second, tm = ((*it3).first - dot[cur].x) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
auto it4 = it3++; diag[1][id1][1].erase(it4);
}
}
else if (dir[cur] == 1) {
int least = dot[cur].x + (now + 1) / 2;
auto it = diag[0][id0][2].lower_bound(make_pair(least, -1));
while (it != diag[0][id0][2].end()) {
int nxt = (*it).second, tm = ((*it).first - dot[cur].x) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
auto it2 = it++; diag[0][id0][2].erase(it2);
}
int bound = dot[cur].x - (now + 1) / 2;
auto it3 = diag[1][id1][0].lower_bound(make_pair(least+1, -1));
if (it3 != diag[1][id1][0].begin()) {
--it3;
while (1) {
int nxt = (*it3).second, tm = (dot[cur].x - (*it3).first) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
if (it3 == diag[1][id1][0].begin()) {
diag[1][id1][0].erase(diag[1][id1][0].begin());
break;
}
auto it4 = it3--; diag[1][id1][0].erase(it4);
}
}
}
else if (dir[cur] == 2) {
int bound = dot[cur].x - (now + 1) / 2; //bound 이하의 것들
auto it = diag[0][id0][1].lower_bound(make_pair(bound+1, -1));
if (it != diag[0][id0][1].begin()) {
--it;
while (1) {
int nxt = (*it).second, tm = (dot[cur].x - (*it).first) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
if (it == diag[0][id0][1].begin()) {
diag[0][id0][1].erase(diag[0][id0][1].begin());
break;
}
auto it2 = it--; diag[0][id0][1].erase(it2);
}
}
auto it3 = diag[1][id1][3].lower_bound(make_pair(bound+1, -1));
if (it3 != diag[1][id1][3].begin()) {
--it3;
while (1) {
int nxt = (*it3).second, tm = (dot[cur].x - (*it3).first) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
if (it3 == diag[1][id1][3].begin()) {
diag[1][id1][3].erase(diag[1][id1][3].begin());
break;
}
auto it4 = it3--; diag[1][id1][3].erase(it4);
}
}
}
else {
int least = dot[cur].x + (now + 1) / 2;
auto it = diag[1][id1][2].lower_bound(make_pair(least, -1));
while (it != diag[1][id1][2].end()) {
int nxt = (*it).second, tm = ((*it).first - dot[cur].x) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
auto it2 = it++; diag[1][id1][2].erase(it2);
}
int bound = dot[cur].x - (now + 1) / 2;
auto it3 = diag[0][id0][0].lower_bound(make_pair(least+1, -1));
if (it3 != diag[0][id0][0].begin()) {
--it3;
while (1) {
int nxt = (*it3).second, tm = (dot[cur].x - (*it3).first) * 2;
if (dis[nxt] > tm) {
dis[nxt] = tm;
pq.push(make_pair(-tm, nxt));
}
if (it3 == diag[0][id0][0].begin()) {
diag[0][id0][0].erase(diag[0][id0][0].begin());
break;
}
auto it4 = it3--; diag[0][id0][0].erase(it4);
}
}
}
}
int res = 0;
for (int i = 1; i <= N; i++) res += (dis[i] != inf);
ans = max(ans, res);
}
cout << ans << '\n';
}
Compilation message
fever.cpp: In function 'int main()':
fever.cpp:158:21: warning: unused variable 'bound' [-Wunused-variable]
158 | int bound = dot[cur].x - (now + 1) / 2;
| ^~~~~
fever.cpp:222:21: warning: unused variable 'bound' [-Wunused-variable]
222 | int bound = dot[cur].x - (now + 1) / 2;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
18 ms |
37844 KB |
Output is correct |
3 |
Correct |
19 ms |
37852 KB |
Output is correct |
4 |
Correct |
19 ms |
37920 KB |
Output is correct |
5 |
Correct |
19 ms |
37888 KB |
Output is correct |
6 |
Correct |
18 ms |
37844 KB |
Output is correct |
7 |
Correct |
27 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37844 KB |
Output is correct |
9 |
Correct |
19 ms |
37844 KB |
Output is correct |
10 |
Correct |
19 ms |
37868 KB |
Output is correct |
11 |
Correct |
19 ms |
37840 KB |
Output is correct |
12 |
Correct |
18 ms |
37804 KB |
Output is correct |
13 |
Correct |
20 ms |
37804 KB |
Output is correct |
14 |
Correct |
19 ms |
37892 KB |
Output is correct |
15 |
Correct |
20 ms |
37924 KB |
Output is correct |
16 |
Correct |
18 ms |
37912 KB |
Output is correct |
17 |
Correct |
23 ms |
37876 KB |
Output is correct |
18 |
Correct |
18 ms |
37824 KB |
Output is correct |
19 |
Correct |
19 ms |
37868 KB |
Output is correct |
20 |
Correct |
18 ms |
37904 KB |
Output is correct |
21 |
Correct |
18 ms |
37852 KB |
Output is correct |
22 |
Correct |
18 ms |
37920 KB |
Output is correct |
23 |
Correct |
20 ms |
37896 KB |
Output is correct |
24 |
Correct |
18 ms |
37864 KB |
Output is correct |
25 |
Correct |
18 ms |
37912 KB |
Output is correct |
26 |
Correct |
22 ms |
37792 KB |
Output is correct |
27 |
Correct |
18 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37872 KB |
Output is correct |
29 |
Correct |
17 ms |
37844 KB |
Output is correct |
30 |
Incorrect |
18 ms |
37844 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
18 ms |
37844 KB |
Output is correct |
3 |
Correct |
19 ms |
37852 KB |
Output is correct |
4 |
Correct |
19 ms |
37920 KB |
Output is correct |
5 |
Correct |
19 ms |
37888 KB |
Output is correct |
6 |
Correct |
18 ms |
37844 KB |
Output is correct |
7 |
Correct |
27 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37844 KB |
Output is correct |
9 |
Correct |
19 ms |
37844 KB |
Output is correct |
10 |
Correct |
19 ms |
37868 KB |
Output is correct |
11 |
Correct |
19 ms |
37840 KB |
Output is correct |
12 |
Correct |
18 ms |
37804 KB |
Output is correct |
13 |
Correct |
20 ms |
37804 KB |
Output is correct |
14 |
Correct |
19 ms |
37892 KB |
Output is correct |
15 |
Correct |
20 ms |
37924 KB |
Output is correct |
16 |
Correct |
18 ms |
37912 KB |
Output is correct |
17 |
Correct |
23 ms |
37876 KB |
Output is correct |
18 |
Correct |
18 ms |
37824 KB |
Output is correct |
19 |
Correct |
19 ms |
37868 KB |
Output is correct |
20 |
Correct |
18 ms |
37904 KB |
Output is correct |
21 |
Correct |
18 ms |
37852 KB |
Output is correct |
22 |
Correct |
18 ms |
37920 KB |
Output is correct |
23 |
Correct |
20 ms |
37896 KB |
Output is correct |
24 |
Correct |
18 ms |
37864 KB |
Output is correct |
25 |
Correct |
18 ms |
37912 KB |
Output is correct |
26 |
Correct |
22 ms |
37792 KB |
Output is correct |
27 |
Correct |
18 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37872 KB |
Output is correct |
29 |
Correct |
17 ms |
37844 KB |
Output is correct |
30 |
Incorrect |
18 ms |
37844 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
20 ms |
37896 KB |
Output is correct |
3 |
Correct |
17 ms |
37892 KB |
Output is correct |
4 |
Correct |
19 ms |
37904 KB |
Output is correct |
5 |
Correct |
18 ms |
37884 KB |
Output is correct |
6 |
Correct |
19 ms |
37936 KB |
Output is correct |
7 |
Correct |
19 ms |
37840 KB |
Output is correct |
8 |
Incorrect |
19 ms |
37908 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
18 ms |
37844 KB |
Output is correct |
3 |
Correct |
19 ms |
37852 KB |
Output is correct |
4 |
Correct |
19 ms |
37920 KB |
Output is correct |
5 |
Correct |
19 ms |
37888 KB |
Output is correct |
6 |
Correct |
18 ms |
37844 KB |
Output is correct |
7 |
Correct |
27 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37844 KB |
Output is correct |
9 |
Correct |
19 ms |
37844 KB |
Output is correct |
10 |
Correct |
19 ms |
37868 KB |
Output is correct |
11 |
Correct |
19 ms |
37840 KB |
Output is correct |
12 |
Correct |
18 ms |
37804 KB |
Output is correct |
13 |
Correct |
20 ms |
37804 KB |
Output is correct |
14 |
Correct |
19 ms |
37892 KB |
Output is correct |
15 |
Correct |
20 ms |
37924 KB |
Output is correct |
16 |
Correct |
18 ms |
37912 KB |
Output is correct |
17 |
Correct |
23 ms |
37876 KB |
Output is correct |
18 |
Correct |
18 ms |
37824 KB |
Output is correct |
19 |
Correct |
19 ms |
37868 KB |
Output is correct |
20 |
Correct |
18 ms |
37904 KB |
Output is correct |
21 |
Correct |
18 ms |
37852 KB |
Output is correct |
22 |
Correct |
18 ms |
37920 KB |
Output is correct |
23 |
Correct |
20 ms |
37896 KB |
Output is correct |
24 |
Correct |
18 ms |
37864 KB |
Output is correct |
25 |
Correct |
18 ms |
37912 KB |
Output is correct |
26 |
Correct |
22 ms |
37792 KB |
Output is correct |
27 |
Correct |
18 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37872 KB |
Output is correct |
29 |
Correct |
17 ms |
37844 KB |
Output is correct |
30 |
Incorrect |
18 ms |
37844 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
18 ms |
37844 KB |
Output is correct |
3 |
Correct |
19 ms |
37852 KB |
Output is correct |
4 |
Correct |
19 ms |
37920 KB |
Output is correct |
5 |
Correct |
19 ms |
37888 KB |
Output is correct |
6 |
Correct |
18 ms |
37844 KB |
Output is correct |
7 |
Correct |
27 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37844 KB |
Output is correct |
9 |
Correct |
19 ms |
37844 KB |
Output is correct |
10 |
Correct |
19 ms |
37868 KB |
Output is correct |
11 |
Correct |
19 ms |
37840 KB |
Output is correct |
12 |
Correct |
18 ms |
37804 KB |
Output is correct |
13 |
Correct |
20 ms |
37804 KB |
Output is correct |
14 |
Correct |
19 ms |
37892 KB |
Output is correct |
15 |
Correct |
20 ms |
37924 KB |
Output is correct |
16 |
Correct |
18 ms |
37912 KB |
Output is correct |
17 |
Correct |
23 ms |
37876 KB |
Output is correct |
18 |
Correct |
18 ms |
37824 KB |
Output is correct |
19 |
Correct |
19 ms |
37868 KB |
Output is correct |
20 |
Correct |
18 ms |
37904 KB |
Output is correct |
21 |
Correct |
18 ms |
37852 KB |
Output is correct |
22 |
Correct |
18 ms |
37920 KB |
Output is correct |
23 |
Correct |
20 ms |
37896 KB |
Output is correct |
24 |
Correct |
18 ms |
37864 KB |
Output is correct |
25 |
Correct |
18 ms |
37912 KB |
Output is correct |
26 |
Correct |
22 ms |
37792 KB |
Output is correct |
27 |
Correct |
18 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37872 KB |
Output is correct |
29 |
Correct |
17 ms |
37844 KB |
Output is correct |
30 |
Incorrect |
18 ms |
37844 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
18 ms |
37844 KB |
Output is correct |
3 |
Correct |
19 ms |
37852 KB |
Output is correct |
4 |
Correct |
19 ms |
37920 KB |
Output is correct |
5 |
Correct |
19 ms |
37888 KB |
Output is correct |
6 |
Correct |
18 ms |
37844 KB |
Output is correct |
7 |
Correct |
27 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37844 KB |
Output is correct |
9 |
Correct |
19 ms |
37844 KB |
Output is correct |
10 |
Correct |
19 ms |
37868 KB |
Output is correct |
11 |
Correct |
19 ms |
37840 KB |
Output is correct |
12 |
Correct |
18 ms |
37804 KB |
Output is correct |
13 |
Correct |
20 ms |
37804 KB |
Output is correct |
14 |
Correct |
19 ms |
37892 KB |
Output is correct |
15 |
Correct |
20 ms |
37924 KB |
Output is correct |
16 |
Correct |
18 ms |
37912 KB |
Output is correct |
17 |
Correct |
23 ms |
37876 KB |
Output is correct |
18 |
Correct |
18 ms |
37824 KB |
Output is correct |
19 |
Correct |
19 ms |
37868 KB |
Output is correct |
20 |
Correct |
18 ms |
37904 KB |
Output is correct |
21 |
Correct |
18 ms |
37852 KB |
Output is correct |
22 |
Correct |
18 ms |
37920 KB |
Output is correct |
23 |
Correct |
20 ms |
37896 KB |
Output is correct |
24 |
Correct |
18 ms |
37864 KB |
Output is correct |
25 |
Correct |
18 ms |
37912 KB |
Output is correct |
26 |
Correct |
22 ms |
37792 KB |
Output is correct |
27 |
Correct |
18 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37872 KB |
Output is correct |
29 |
Correct |
17 ms |
37844 KB |
Output is correct |
30 |
Incorrect |
18 ms |
37844 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
18 ms |
37844 KB |
Output is correct |
3 |
Correct |
19 ms |
37852 KB |
Output is correct |
4 |
Correct |
19 ms |
37920 KB |
Output is correct |
5 |
Correct |
19 ms |
37888 KB |
Output is correct |
6 |
Correct |
18 ms |
37844 KB |
Output is correct |
7 |
Correct |
27 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37844 KB |
Output is correct |
9 |
Correct |
19 ms |
37844 KB |
Output is correct |
10 |
Correct |
19 ms |
37868 KB |
Output is correct |
11 |
Correct |
19 ms |
37840 KB |
Output is correct |
12 |
Correct |
18 ms |
37804 KB |
Output is correct |
13 |
Correct |
20 ms |
37804 KB |
Output is correct |
14 |
Correct |
19 ms |
37892 KB |
Output is correct |
15 |
Correct |
20 ms |
37924 KB |
Output is correct |
16 |
Correct |
18 ms |
37912 KB |
Output is correct |
17 |
Correct |
23 ms |
37876 KB |
Output is correct |
18 |
Correct |
18 ms |
37824 KB |
Output is correct |
19 |
Correct |
19 ms |
37868 KB |
Output is correct |
20 |
Correct |
18 ms |
37904 KB |
Output is correct |
21 |
Correct |
18 ms |
37852 KB |
Output is correct |
22 |
Correct |
18 ms |
37920 KB |
Output is correct |
23 |
Correct |
20 ms |
37896 KB |
Output is correct |
24 |
Correct |
18 ms |
37864 KB |
Output is correct |
25 |
Correct |
18 ms |
37912 KB |
Output is correct |
26 |
Correct |
22 ms |
37792 KB |
Output is correct |
27 |
Correct |
18 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37872 KB |
Output is correct |
29 |
Correct |
17 ms |
37844 KB |
Output is correct |
30 |
Incorrect |
18 ms |
37844 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |