# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
130361 | reda | Pictionary (COCI18_pictionary) | C++14 | 1562 ms | 1528 KiB |
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>
#pragma GCC optimize ("O3")
#define endl '\n'
#define MAXN 1005
using namespace std;
int Arr[MAXN];
int Arr2[MAXN];
int n;
void init()
{
for(int i=1;i<=n;i++)
{
Arr[i] = i;
Arr2[i] = 0;
}
}
int Find(int x)
{
while(Arr[x] != x)
{
Arr[x]=Arr[Arr[x]] ;
x=Arr[x];
}
return x;
}
void Union (int a, int b)
{
a = Find(a);
b = Find(b);
if(Arr2[a] == Arr2[b])
Arr2[b]++;
else if(Arr2[a] > Arr2[b])
swap(a, b);
Arr[a] = b;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q , m ;
cin>>n>>m>>q;
while(q--)
{
int a, b;
cin>>a>>b;
init();
int j;
for(j=m;j>=1;j--)
{
for(int i=2;i*j<=n;i++)
if(Find(j)!=Find(i*j))
Union(j, i*j);
if(Find(a)==Find(b))
break;
}
cout<<m-j+1<<endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |