Submission #853050

# Submission time Handle Problem Language Result Execution time Memory
853050 2023-09-23T11:05:53 Z aykhn Gondola (IOI14_gondola) C++14
100 / 100
38 ms 7116 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define pb push_back
#define ins insert
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define fi first
#define se second

const int mod = 1e9 + 9;

int mult(ll a, ll b)
{
    return (a * b) % mod;
}

int binpow(ll a, ll b)
{
    a %= mod;
    ll res = 1;
    while (b)
    {
        if (b & 1) res = mult(res, a);
        b >>= 1;
        a = mult(a, a);
    }
    return res;
}

vector<int> ASDASD;

int ok(vector<int> &v)
{
    int n = v.size();
    set<int> s;
    for (int x : v) s.ins(x);
    if (s.size() != v.size()) return 0;
    vector<int> a(n, 0);
    int anc = -1;
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] <= n) 
        {
            anc = i;
            break;
        }
    }
    if (anc == -1) 
    {
        ASDASD = v;
        return 1;
    }
    int shift = n + v[anc] - anc - 1;
    for (int i = 0; i < n; i++) a[(i + shift + 10*n) % n] = v[i];
    ASDASD = a;
    for (int i = 0; i < n; i++)
    {
        if (a[i] <= n && a[i] != i + 1) return 0;
    }
    return 1;
}

int valid(int n, int in[])
{
    vector<int> v;
    for (int i = 0; i < n; i++) v.pb(in[i]);
    return ok(v);
}

int replacement(int n, int in[], int ret[])
{
    vector<int> v;
    for (int i = 0; i < n; i++) v.pb(in[i]);
    ok(v);
    v = ASDASD;
    vector<pii> a;
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] == i + 1) continue;
        a.pb(mpr(v[i], i + 1));
    }
    sort(all(a));
    int j = 0;
    int rn = n + 1;
    for (int i = 0; i < a.size(); i++)
    {
        ret[j++] = a[i].se;
        while (a[i].fi > rn) ret[j++] = rn++;
        rn++;
    }
    return j;
}

int countReplacement(int n, int in[])
{
    vector<int> v;
    for (int i = 0; i < n; i++) v.pb(in[i]);
    if (!ok(v)) return 0;
    v = ASDASD;
    vector<pii> a;
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] == i + 1) continue;
        a.pb(mpr(v[i], i + 1));
    }
    int x = 1;
    if (a.size() == v.size()) x = n;
    sort(all(a));
    int last = n;
    int res = 1;
    int sz = a.size();
    for (int i = 0; i < a.size(); i++) 
    {
        res = mult(res, binpow(sz - i, a[i].fi - last - 1));
        last = a[i].fi;
    }
    return mult(res, x);
}

Compilation message

gondola.cpp: In function 'int ok(std::vector<int>&)':
gondola.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
gondola.cpp:93:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:109:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
gondola.cpp:120:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 9 ms 2776 KB Output is correct
7 Correct 20 ms 4052 KB Output is correct
8 Correct 15 ms 4816 KB Output is correct
9 Correct 5 ms 1880 KB Output is correct
10 Correct 19 ms 5580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 11 ms 2772 KB Output is correct
7 Correct 20 ms 4052 KB Output is correct
8 Correct 15 ms 4820 KB Output is correct
9 Correct 6 ms 1880 KB Output is correct
10 Correct 20 ms 5588 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 10 ms 2516 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 26 ms 5664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 17 ms 5328 KB Output is correct
12 Correct 20 ms 5840 KB Output is correct
13 Correct 20 ms 3012 KB Output is correct
14 Correct 19 ms 5328 KB Output is correct
15 Correct 20 ms 2960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 27 ms 5328 KB Output is correct
10 Correct 21 ms 4616 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 11 ms 2136 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 28 ms 5320 KB Output is correct
10 Correct 21 ms 4564 KB Output is correct
11 Correct 8 ms 1880 KB Output is correct
12 Correct 10 ms 2136 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 33 ms 6344 KB Output is correct
15 Correct 38 ms 7116 KB Output is correct
16 Correct 6 ms 1624 KB Output is correct
17 Correct 24 ms 4812 KB Output is correct
18 Correct 13 ms 3176 KB Output is correct