This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 k=0;k<10;k++){
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 (stderr)
Main.cpp: In function 'int main()':
Main.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
Main.cpp:46:28: 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |