Submission #521527

# Submission time Handle Problem Language Result Execution time Memory
521527 2022-02-02T11:10:08 Z amunduzbaev IOI Fever (JOI21_fever) C++14
6 / 100
2 ms 716 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);
		x[p[i][0]].push_back(i);
		y[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(auto& [x, v] : m2){
		sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][0] < p[j][0]); });
	} for(auto& [x, v] : x){
		sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][1] < p[j][1]); });
	} for(auto& [x, v] : y){
		sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][0] < p[j][0]); });
	}
	
	int ans = 0;
	for(int t=0;t<4;t++){
		auto t1 = m1, t2 = m2;
		vector<int> T(n, 1e18); 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()){
			auto u = qq.top(); qq.pop();
			int i = u[2], t = u[1];
			//~ for(int j=0;j<n;j++){
				//~ if(t == 0){
				//~ } if(t == 1){
					
				//~ } if(t == 2){
					
				//~ } if(t == 3){
					
				//~ }
			//~ }
			
			//~ 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]) * 2 < T[i]) break;
						v.pop_front();
						if(T[x] > abs(p[i][0] - p[x][0]) * 2){
							T[x] = abs(p[i][0] - p[x][0]) * 2;
							qq.push({T[x], 1, x});
						}
					} if(t == 1){
						int x = v.back();
						if((p[x][0] - p[i][0]) * 2 < T[i]) break;
						v.pop_back();
						if(T[x] > abs(p[i][0] - p[x][0]) * 2){
							T[x] = abs(p[i][0] - p[x][0]) * 2;
							qq.push({T[x], 0, x});
						}
					} if(t == 2){
						int x = v.back();
						if((p[x][0] - p[i][0]) * 2 < T[i]) break;
						v.pop_back();
						if(T[x] > 2 * abs(p[i][0] - p[x][0])){
							T[x] = 2 * 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]) * 2 < T[i]) break;
						v.pop_front();
						if(T[x] > 2 * abs(p[i][0] - p[x][0])){
							T[x] = 2 * 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(2 * (p[x][0] - p[i][0]) < T[i]) break;
						v.pop_back();
						if(T[x] > 2 * abs(p[i][0] - p[x][0])){
							T[x] = 2 * abs(p[i][0] - p[x][0]);
							qq.push({T[x], 3, x});
						}
					} if(t == 1){
						int x = v.back();
						if(2 * (p[x][0] - p[i][0]) < T[i]) break;
						v.pop_back();
						if(T[x] > 2 * abs(p[i][0] - p[x][0])){
							T[x] = 2 * abs(p[i][0] - p[x][0]);
							qq.push({T[x], 2, x});
						}
					} if(t == 2){
						int x = v.front();
						if(2 * (p[i][0] - p[x][0]) < T[i]) break;
						v.pop_front();
						if(T[x] > 2 * abs(p[i][0] - p[x][0])){
							T[x] = 2 * abs(p[i][0] - p[x][0]);
							qq.push({T[x], 1, x});
						}
					} if(t == 3){
						int x = v.front();
						if(2 * (p[i][0] - p[x][0]) < T[i]) break;
						v.pop_front();
						if(T[x] > 2 * abs(p[i][0] - p[x][0])){
							T[x] = 2 * abs(p[i][0] - p[x][0]);
							qq.push({T[x], 0, x});
						}
					}
				} 
				swap(tmp, v);
			}
			
			if(t&1){
				auto& v = y[p[i][0]];
				for(auto x : v){
					if(t == 1 && T[i] <= p[x][0] - p[i][0] && T[x] > p[x][0] - p[i][0]){
						T[x] = p[x][0] - p[i][0];
						qq.push({T[x], 3, x});
					} if(t == 3 && T[i] <= p[i][0] - p[x][0] && T[x] > p[i][0] - p[x][0]){
						T[x] = p[i][0] - p[x][0];
						qq.push({T[x], 1, x});
					}
				}
			} else {
				auto& v = x[p[i][1]];
				for(auto x : v){
					if(t == 0 && T[i] <= p[x][1] - p[i][1] && T[x] > p[x][1] - p[i][1]){
						T[x] = p[x][1] - p[i][1];
						qq.push({T[x], 2, x});
					} if(t == 2 && T[i] <= p[i][1] - p[x][1] && T[x] > p[i][1] - p[x][1]){
						T[x] = p[i][1] - p[x][1];
						qq.push({T[x], 0, x});
					}
				}
			}
		}
		
		for(int i=0;i<n;i++){
			res += (T[i] < 1e18);
		}
		
		ans = max(ans, res);
		m1 = t1, m2 = t2;
	}
	
	cout<<ans<<"\n";
}

Compilation message

fever.cpp: In function 'int main()':
fever.cpp:21:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |  for(auto& [x, v] : m1){
      |            ^
fever.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |  } for(auto& [x, v] : m2){
      |              ^
fever.cpp:25:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |  } for(auto& [x, v] : x){
      |              ^
fever.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |  } for(auto& [x, v] : y){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 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 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 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 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 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 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 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 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 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 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 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 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -