Submission #373477

# Submission time Handle Problem Language Result Execution time Memory
373477 2021-03-04T19:04:50 Z idk321 Gondola (IOI14_gondola) C++11
100 / 100
72 ms 6124 KB
#include "gondola.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int M = 250005;

const int mod = 1000000009;

int valid(int n, int seq[])
{
    set<int> vis;
    for (int i = 0; i < n; i++)
    {
        if (vis.find(seq[i]) != vis.end()) return 0;
        vis.insert(seq[i]);
    }


    int cur = -1;
    for (int i = 0; i < n; i++) seq[i]--;
  for (int i = 0; i < n; i++)
  {
    if (seq[i] < n)
    {
        cur = i;
        break;
    }



  }

    if (cur == -1) return 1;

    int val = seq[cur];
    for (int i = cur + 1; i < n; i++)
    {
        val++;
        val %= n;

        if (seq[i] < n && seq[i] != val) return 0;
    }


    return 1;

}

//----------------------

int replacement(int n, int seq[], int seq2[])
{
    vector<int> to(M, -1);
    int biggest = -1;
    int cbig = -1;
    for (int i = 0; i < n; i++)
    {
        seq[i]--;
        to[seq[i]] = i;
        if (seq[i] > cbig)
        {
            cbig = seq[i];
            biggest = i;
        }

    }

    if (cbig == n - 1) return 0;
    int org[M];
    for (int i = 0; i < n; i++) org[i] = -1;

    for (int i = 0; i < n; i++)
    {
        if (seq[i] < n)
        {
            for (int j = 0; j < n; j++)
            {
                org[j] = ((seq[i] - (i - j)) % n + n) % n;
            }
            break;
        }
    }

    if (org[0] == -1)
    {
        for (int i = 0; i < n; i++) org[i] = i;
    }


    int cur = 0;
    for (int cnum = n; cnum <= cbig; cnum++)
    {
        if (to[cnum] == -1)
        {
            seq2[cur] = org[biggest] + 1;
            org[biggest] = cnum;
        } else
        {
            seq2[cur] = org[to[cnum]] + 1;
            org[to[cnum]] = cnum;
        }

        cur++;
    }


  return cur++;
}

/*
4
2
10 11
*/

//----------------------

int expo(int num, int p)
{
    ll cur = num;
    ll res = 1;
    while (p > 0)
    {
        if (p % 2 == 0)
        {
            p /= 2;
            cur *= cur;
            cur %= mod;

        } else
        {
            res *= cur;
            res %= mod;
            p--;
        }
    }


    return res;
}

int countReplacement(int n, int seq[])
{


    if (!valid(n, seq)) return 0;

    vector<int> big;
    int open = 0;
    for (int i = 0; i < n; i++)
    {
        if (seq[i] >= n)
        {
            open++;
            big.push_back(seq[i]);
        }

    }



    bool allBigger = true;
    for (int i = 0; i < n; i++) if (seq[i] < n) allBigger = false;

    long long res = 1;
    if (allBigger) res = n;
    big.push_back(n - 1);
    sort(big.begin(), big.end());
    for (int i = 1; i < big.size(); i++)
    {
        int dist = big[i] - big[i - 1] - 1;
        res *= expo(open, dist);
        res %= mod;
        open--;
    }


  return res;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:171:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |     for (int i = 1; i < big.size(); i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 2540 KB Output is correct
7 Correct 12 ms 1004 KB Output is correct
8 Correct 31 ms 4332 KB Output is correct
9 Correct 9 ms 1644 KB Output is correct
10 Correct 36 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 15 ms 2412 KB Output is correct
7 Correct 11 ms 1004 KB Output is correct
8 Correct 32 ms 4204 KB Output is correct
9 Correct 9 ms 1644 KB Output is correct
10 Correct 36 ms 4844 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 20 ms 2284 KB Output is correct
14 Correct 1 ms 380 KB Output is correct
15 Correct 51 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1260 KB Output is correct
10 Correct 2 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1260 KB Output is correct
10 Correct 2 ms 1408 KB Output is correct
11 Correct 11 ms 2028 KB Output is correct
12 Correct 13 ms 1900 KB Output is correct
13 Correct 15 ms 2156 KB Output is correct
14 Correct 11 ms 1900 KB Output is correct
15 Correct 24 ms 2328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 48 ms 4076 KB Output is correct
10 Correct 38 ms 3436 KB Output is correct
11 Correct 14 ms 1516 KB Output is correct
12 Correct 17 ms 1772 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 48 ms 4076 KB Output is correct
10 Correct 37 ms 3436 KB Output is correct
11 Correct 15 ms 1516 KB Output is correct
12 Correct 17 ms 1672 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 62 ms 4588 KB Output is correct
15 Correct 72 ms 6124 KB Output is correct
16 Correct 11 ms 1388 KB Output is correct
17 Correct 45 ms 4204 KB Output is correct
18 Correct 24 ms 2540 KB Output is correct