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 fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 22;
const ll MAXN = 1005;
vector<ll> v;
set<int> graph[MAXN];
int ans[MAXN][MAXN], dist[MAXN];
void dfs(int node, int frog) {
if (dist[node] == 3)
return ;
vector<int> omit;
for (auto u : graph[node]) {
if (dist[u] == -1) {
dist[u] = dist[node] + 1;
omit.push_back(u);
dfs(u, frog);
} else if (dist[u] >= dist[node] + 1)
omit.push_back(u);
}
for (auto u : omit) {
ans[node][u] = frog;
graph[node].erase(u);
}
}
int main() {
fast
int n;
cin >> n;
v = vector<ll>(n+1);
for (int i = 1; i <= n; i++)
cin >> v[i];
for (int i = 1; i <= n; i++) {
for (int j = i+1; j <= n; j++) {
if (v[j] % v[i] == 0)
graph[i].insert(j);
else
ans[i][j] = 1;
}
}
for (int rep = 0; rep < 30; rep++) {
for (int frog = 1; frog <= 3; frog++) {
memset(dist, -1, sizeof(dist));
for (int node = 1; node <= n; node++) {
if (dist[node] == -1) {
dist[node] = 0;
dfs(node, frog);
}
}
}
}
for (int i = 1; i <= n-1; i++) {
for (int j = 1; j <= i; j++)
cout << ans[j][i+1] << " ";
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |