답안 #521420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521420 2022-02-02T06:01:22 Z amunduzbaev IOI 바이러스 (JOI21_fever) C++14
6 / 100
1 ms 588 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
#define int long long

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<ar<int, 2>> p(n);
	for(int i=0;i<n;i++) cin>>p[i][0]>>p[i][1];
	map<int, deque<int>> m1, m2, x, y;
	for(int i=0;i<n;i++){
		m1[p[i][0] + p[i][1]].push_back(i);
		m2[p[i][0] - p[i][1]].push_back(i);
	}
	
	for(auto& [x, v] : m1){
		sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][0] < p[j][0]); });
		//~ for(int i=0;i<(int)v.size();i++) p1[v[i]] = i;
	}
	
	for(auto& [x, v] : m2){
		sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][0] < p[j][0]); });
		//~ for(int i=0;i<(int)v.size();i++) p2[v[i]] = i;
	}
	
	int ans = 0;
	for(int t=0;t<4;t++){
		auto t1 = m1, t2 = m2;
		vector<int> T(n, 2e9); T[0] = 0;
		priority_queue<ar<int, 3>, vector<ar<int, 3>>, greater<ar<int, 3>>> qq; qq.push({0, t, 0});
		int res = 0;
		while(!qq.empty()){
			res++;
			auto u = qq.top(); qq.pop();
			int i = u[2], t = u[1];
			if(u[0] > T[i]) continue;
			{
				auto& v = m1[p[i][0] + p[i][1]];
				auto tmp = v;
				while(!v.empty()){
					if(t == 0){
						int x = v.front();
						if(p[i][0] - p[x][0] < T[i]) break;
						v.pop_front();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 1, x});
						}
					} if(t == 1){
						int x = v.back();
						if(p[x][0] - p[i][0] < T[i]) break;
						v.pop_back();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 0, x});
						}
					} if(t == 2){
						int x = v.back();
						if(p[x][0] - p[i][0] < T[i]) break;
						v.pop_back();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 3, x});
						}
					} if(t == 3){
						int x = v.front();
						if(p[i][0] - p[x][0] < T[i]) break;
						v.pop_front();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 2, x});
						}
					}
				} swap(tmp, v);
			}
			
			{
				auto& v = m2[p[i][0] - p[i][1]];
				auto tmp = v;
				while(!v.empty()){
					if(t == 0){
						int x = v.back();
						if(p[x][0] - p[i][0] < T[i]) break;
						v.pop_back();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 3, x});
						}
					} if(t == 1){
						int x = v.back();
						if(p[x][0] - p[i][0] < T[i]) break;
						v.pop_back();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 2, x});
						}
					} if(t == 2){
						int x = v.front();
						if(p[i][0] - p[x][0] < T[i]) break;
						v.pop_front();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 1, x});
						}
					} if(t == 3){
						int x = v.front();
						if(p[i][0] - p[x][0] < T[i]) break;
						v.pop_front();
						if(T[x] > abs(p[i][0] - p[x][0])){
							T[x] = abs(p[i][0] - p[x][0]);
							qq.push({T[x], 0, x});
						}
					}
				} swap(tmp, v);
			}
			
			//~ if(!u1.count(p[i][0] + p[i][1])){
				//~ if(v.back() == i && (d == 1 || d == 2));
				//~ else if(v[0] == i && (d == 0 || d == 3));
				//~ else {
					//~ int dd = (d < 2 ? 1 : 2);
					//~ for(auto x : v){
						//~ if(x == i) dd = (d < 2 ? 0 : 3);
						//~ if(used[x]) continue;
						//~ used[x] = 1;
						//~ qq.push({x, dd});
					//~ }
					//~ u1.insert(p[i][0] + p[i][1]);
				//~ }
			//~ }
			
			//~ if(!u2.count(p[i][0] - p[i][1])){
				//~ auto& v = m2[p[i][0] - p[i][1]];
				//~ if(v.back() == i && (d == 0 || d == 1));
				//~ else if(v[0] == i && (d == 2 || d == 3));
				//~ else {
					//~ int dd = (d == 0 || d == 3 ? 0 : 1);
					//~ for(auto x : v){
						//~ if(x == i) dd = (dd == 0 ? 3 : 2);
						//~ if(used[x]) continue;
						//~ used[x] = 1;
						//~ qq.push({x, dd});
					//~ }
					//~ u2.insert(p[i][0] - p[i][1]);
				//~ }
			//~ }
		}
		
		ans = max(ans, res);
		m1 = t1, m2 = t2;
	}
	
	cout<<ans<<"\n";
}

Compilation message

fever.cpp: In function 'int main()':
fever.cpp:19:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |  for(auto& [x, v] : m1){
      |            ^
fever.cpp:24:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |  for(auto& [x, v] : m2){
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Halted 0 ms 0 KB -