답안 #377364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377364 2021-03-14T06:03:38 Z Thistle 식물 비교 (IOI20_plants) C++14
0 / 100
4000 ms 9868 KB
#include "plants.h"
#include <vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<random>
#include<queue>
using namespace std;
using ll=long long;
using H=pair<ll, ll>;
#define vec vector
#define vi vec<ll>
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) rng((i),0,(n))
#define siz(a) int((a).size())

int n;
vec<vec<int>>e;
void init(int k, std::vector<int> r) {
	//DAG kouchiku
	n=siz(r);
	rep(i,n) r.pb(r[i]);

	e.assign(n,vec<int>());

	rep(i,n)rep(_,n){
		if(i==_) continue;
		int j=_;
		if(j<i) j+=n;
		
		if(i+k<=j) continue;
		int t=j-i,mn,mx;
		if(j+k<=i+n){
			mn=max(0,r[j]-t)+1;
			mx=k-1;
		}
		else{
			int step=i+k-j-1;
			mx=k-1;
			mn=max(0,(r[j]-(k-(2*step+2))))+1;
		}
		if(r[i]<mn||mx<r[i]){ 
			e[_].pb(i);
		}

		if(j+k<=i+n){
			mx=t-1+max(0,r[j]-t);
			mn=0;
		}
		else{
			int step=i+k-j-1;
			mn=0;
			mx=n-k+min(2*step, r[j]-1);
		}
		if(r[i]<mn||mx<r[i]){
			e[i].pb(_);
		}
	}

	return;
}

int compare_plants(int x, int y) {
	vec<bool>used(n,0);
	queue<int>q;
	q.push(x);
	used[x]=1;
	while(!q.empty()){
		int t=q.front();q.pop();
		for(auto g:e[t]){
			if(!used[g]){
				used[g]=1;
				q.push(g);
			}
		}
	}
	if(used[y]) return -1;
	used=vec<bool>(n,0);
	used[y]=1;
	q.push(y);
	while(!q.empty()){
		int t=q.front();q.pop();
		for(auto g:e[t]){
			if(!used[g]){
				used[g]=1;
				q.push(g);
			}
		}
	}
	if(used[x]) return 1;
	return 0;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:15:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
plants.cpp:16:18: note: in expansion of macro 'rng'
   16 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
plants.cpp:24:2: note: in expansion of macro 'rep'
   24 |  rep(i,n) r.pb(r[i]);
      |  ^~~
plants.cpp:15:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
plants.cpp:16:18: note: in expansion of macro 'rng'
   16 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
plants.cpp:28:2: note: in expansion of macro 'rep'
   28 |  rep(i,n)rep(_,n){
      |  ^~~
plants.cpp:15:28: warning: unnecessary parentheses in declaration of '_' [-Wparentheses]
   15 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
plants.cpp:16:18: note: in expansion of macro 'rng'
   16 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
plants.cpp:28:10: note: in expansion of macro 'rep'
   28 |  rep(i,n)rep(_,n){
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 89 ms 3180 KB Output is correct
7 Correct 1879 ms 4300 KB Output is correct
8 Execution timed out 4098 ms 9868 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Execution timed out 4027 ms 4652 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 89 ms 3180 KB Output is correct
7 Correct 1879 ms 4300 KB Output is correct
8 Execution timed out 4098 ms 9868 KB Time limit exceeded
9 Halted 0 ms 0 KB -