Submission #238643

# Submission time Handle Problem Language Result Execution time Memory
238643 2020-06-12T08:56:52 Z Vimmer Pictionary (COCI18_pictionary) C++14
56 / 140
1500 ms 3576 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];

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

    for (int x = m; x >= 1; 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)) ans[i] = m - x + 1;
    }

    for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 397 ms 2040 KB Output is correct
2 Correct 200 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 590 ms 3064 KB Output is correct
2 Correct 371 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1575 ms 1536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1587 ms 1792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1590 ms 2296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1584 ms 2936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1560 ms 3064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1594 ms 3576 KB Time limit exceeded
2 Halted 0 ms 0 KB -