답안 #892916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892916 2023-12-26T07:26:02 Z shoryu386 Trampoline (info1cup20_trampoline) C++17
73 / 100
2000 ms 148576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MAXN 600007
vector<int> adj[MAXN];
bool vis[MAXN];

void dfs(int u) {
	for(int v: adj[u]) {
		if(!vis[v]) {
			vis[v] = 1;
			dfs(v);
		}
	}
}


main(){
	int r, c, n; cin >> r >> c >> n;
	
	//r and c are useless lmao
	int N = 0;
	map<int, set< pair<int, bool> >> importantPts; int a, b;
	map<int, set<int>> trampolines;
	for (int x = 0; x < n; x++){
		cin >> a >> b;
		importantPts[a].insert({b, 1}); //1 indicating green trampoline
		importantPts[a+1].insert({b, 0});
		
		trampolines[a].insert(b);
		N++; N++;
	}
	
	int q; cin >> q;
	pair<int, int> starts[q], ends[q]; 
	for (int x = 0; x < q; x++){
		cin >> starts[x].first >> starts[x].second >> ends[x].first >> ends[x].second;
		
		importantPts[ends[x].first].insert({ends[x].second, 0});
		N++;
	}

	map<pair<int, int>, int> coordToNode;
	pair<int, int> hmm[N];
	
	int cnt = 0;
	for (auto y : importantPts){
		for (auto z : y.second){
			coordToNode[{y.first, z.first}] = cnt;
			hmm[cnt] = {y.first, z.first};
			cnt++;
		}
	}
	
	for (auto y : importantPts){ //gen DAG
	
		pair<int, int> lastCoords = {-1, -1};
	
		for (auto z : y.second){
			if (lastCoords.first != -1) adj[coordToNode[lastCoords]].push_back(coordToNode[{y.first, z.first}]);
			
			if (z.second){
				adj[coordToNode[{y.first, z.first}]].push_back(coordToNode[{y.first+1, z.first}]);
			}
			lastCoords = {y.first, z.first};
		}
	}
	
	for (int x = 0; x < q; x++){
		auto startTramp = importantPts[starts[x].first].lower_bound({starts[x].second, 0});
		
		if (starts[x].first > ends[x].first || startTramp == importantPts[starts[x].first].end()){
			cout << "No\n"; continue;
		}
		
		int startF = starts[x].first, startS = startTramp->first;
		bool found = false;
		while (startF != ends[x].first){
			auto lb = trampolines[startF].lower_bound(startS);
			if (lb != trampolines[startF].end()){
				startF++;
				startS = *lb;
			}
			else break;
		}
		
		if (startF == ends[x].first && startS <= ends[x].second) found = true;
		
		if (found) cout << "Yes\n";
		else cout << "No\n";
	}
	
	
	
}

Compilation message

trampoline.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 18268 KB 200 token(s): yes count is 21, no count is 179
2 Correct 22 ms 18512 KB 200 token(s): yes count is 70, no count is 130
3 Correct 16 ms 17524 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 93956 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 696 ms 94032 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 914 ms 80720 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 1130 ms 93996 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 1604 ms 148576 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 1612 ms 139736 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 1507 ms 134904 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 1450 ms 134988 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 1475 ms 134740 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1525 ms 145752 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 17752 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 28 ms 17752 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 23 ms 19188 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 24 ms 18040 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 245 ms 18200 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 23 ms 18004 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2053 ms 146524 KB Time limit exceeded
2 Halted 0 ms 0 KB -