Submission #538273

# Submission time Handle Problem Language Result Execution time Memory
538273 2022-03-16T13:09:47 Z jamielim Hop (COCI21_hop) C++14
0 / 110
2 ms 4308 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n;
ll arr[1005];
int ans[1005][1005];
set<int> adj[1005]; // graph of division thingy is a dag
int dist[1005];

void dfs(int x,int f){
	if(dist[x]==3)return;
	vector<int> to_remove;
	for(int i:adj[x]){
		//printf("%d %d %d %d\n",i,x,dist[i],dist[x]);
		if(dist[i]==-1){
			to_remove.pb(i);
			dist[i]=dist[x]+1;
			dfs(i,f);
		}else if(dist[i]>dist[x]){
			to_remove.pb(i);
		}
	}
	for(int i:to_remove){
		adj[x].erase(i);
		ans[x][i]=f;
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
	memset(ans,-1,sizeof(ans));
	for(int i=1;i<n;i++){
		for(int j=0;j<i;j++){
			if(arr[i]%arr[j]!=0){
				ans[j][i]=3;
			}else{
				adj[j].insert(i);
			}
		}
	}
	
	for(int f=1;f<=3;f++){
		//draw as many edges as possible such that there is no path of length >3
		memset(dist,-1,sizeof(dist));
		for(int i=0;i<n;i++){
			if(dist[i]==-1){
				dist[i]=0;
				dfs(i,f);
			}
		}
	}
	
	for(int i=1;i<n;i++){
		for(int j=0;j<i;j++){
			printf("%d ",ans[j][i]);
		}
		printf("\n");
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
Main.cpp:46:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
      |                      ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4308 KB Integer -1 violates the range [1, 3]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4308 KB Integer -1 violates the range [1, 3]
2 Halted 0 ms 0 KB -