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>
#define ll long long
using namespace std;
const int N =1005;
ll n,a[N],dp[N][4],col[N][N];
int main()
{
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for (int i=0;i<n;i++)
cin >> a[i];
for (int i=n-2;i>=0;i--) {
for (int j=i+1;j<n;j++) {
if (a[j]%a[i] == 0) {
ll x,y,z;
x = dp[j][1]+1;
y = dp[j][2]+1;
z = dp[j][3]+1;
if (x<=3) {
col[i][j] =1;
dp[i][1] = max(dp[i][1],x);
} else {
if (y<=3) {
col[i][j] = 2;
dp[i][2] = max(dp[i][2],y);
} else {
col[i][j] = 3;
dp[i][3] = max(dp[i][3],z);
}
}
} else {
col[i][j] = 1;
}
}
}
for (int i=1;i<n;i++) {
for (int j=0;j<i;j++) {
cout << col[j][i] << " ";
}
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |