답안 #434352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434352 2021-06-21T03:16:54 Z 20160161simone 식물 비교 (IOI20_plants) C++14
0 / 100
1 ms 332 KB
#include"plants.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll N=2e5+10;
ll n,a[N*2];
struct edge{
	ll to,nxt;
};
vector<edge> ln;
ll topln=0,idx[N],d[N];
void add_edge(ll u,ll v){
	ln.push_back((edge){v,idx[u]}),idx[u]=++topln;
	d[v]++;
}
ll vis[N],val[N],vis2[N];
void topo(ll x,ll k){
	vis[x]=1,val[x]=k;
	for(ll i=idx[x];i;i=ln[i].nxt){
		d[ln[i].to]--;
		if(!d[ln[i].to] && !vis[ln[i].to]) topo(ln[i].to,k-1);
	}
}

void init(int k, vector<int> r) {
	n=r.size();
	ln.push_back((edge){0,0});
	for(ll i=1;i<=n;i++) a[i]=a[i+n]=r[i-1];
	for(ll i=n;i>=1;i--){
		for(ll j=1;j<=n;j++){
			if(a[j]) continue;
			ll f=1;
			for(ll t=j+n-1;t>=j+n-k+1;t--)
				if(!a[t] && !vis2[t]){
					f=0;
					break;
				}
			if(f==0) continue;
			vis2[j]=1;
			if(j>n) vis2[j-n]=1;
			else vis2[j+n]=1;
			for(ll t=j+n-1;t>=j+n-k+1;t--){
				if(vis2[t]) continue;
				if(t<=n) add_edge(j,t),a[t+n]--;
				else add_edge(j,t-n),a[t-n]--;
				a[t]--;
			}
			val[j]=i;
			break;
		}
	}
/*	for(ll i=1;i<=n;i++){
		if(vis[i]) continue;
		if(d[i]==0) topo(i,n);
	}
*/
	for(ll i=1;i<=n;i++) printf("%lld ",val[i]);cout<<endl;
}

int compare_plants(int a, int b) {
	if(val[a+1]>val[b+1]) return 1;
	else return -1;
}









Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:58:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |  for(ll i=1;i<=n;i++) printf("%lld ",val[i]);cout<<endl;
      |  ^~~
plants.cpp:58:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   58 |  for(ll i=1;i<=n;i++) printf("%lld ",val[i]);cout<<endl;
      |                                              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -