답안 #130361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130361 2019-07-15T00:16:52 Z reda Pictionary (COCI18_pictionary) C++14
42 / 140
1500 ms 1528 KB
#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

pictionary.cpp: In function 'int main()':
pictionary.cpp:52:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
                 if(Find(j)!=Find(i*j))
                 ^~
pictionary.cpp:54:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    if(Find(a)==Find(b))
    ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1067 ms 1460 KB Output is correct
2 Correct 853 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1562 ms 1496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 508 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -