답안 #238649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238649 2020-06-12T09:01:59 Z Vimmer Pictionary (COCI18_pictionary) C++14
0 / 140
1500 ms 2296 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 2> a2;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int pr[N], rk[N];

int fnd(int x) {if (pr[x] != x) pr[x] = fnd(pr[x]); return pr[x];}

void link(int a, int b)
{
    if (rk[b] > rk[a]) swap(a, b);

    pr[b] = a;

    rk[a] += rk[b];
}

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m, q;

    cin >> n >> m >> q;

    for (int i = 1; i <= n; i++) {rk[i] = 1; pr[i] = i;}

    vector <pair <int, int> > g(q);

    for (int i = 0; i < q; i++) cin >> g[i].F >> g[i].S;

    int ans[q], kr = 0;

    memset(ans, 0, sizeof(ans));

    for (int x = m; x >= 2 && kr < q; x--)
    {
        for (int j = 1; j <= n / x; j++)
            for (int u = j + 1; u <= n / x; u++)
            {
                int a = fnd(j * x), b = fnd(u * x);

                if (a != b) link(a, b);
            }

        for (int i = 0; i < q; i++)
          if (ans[i] == 0 && fnd(g[i].F) == fnd(g[i].S)) {kr++; ans[i] = m - x + 1;}
    }

    for (int i = 0; i < q; i++) if (ans[i] == 0) ans[i] = 1;

    for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 512 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 636 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 396 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 584 ms 2000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1588 ms 1024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1590 ms 1152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1589 ms 1536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1587 ms 1920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1597 ms 2048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1594 ms 2296 KB Time limit exceeded
2 Halted 0 ms 0 KB -