Submission #296202

# Submission time Handle Problem Language Result Execution time Memory
296202 2020-09-10T11:58:11 Z arayi Gondola (IOI14_gondola) C++17
100 / 100
28 ms 2932 KB
#include <bits/stdc++.h>
#include "gondola.h"
#define ad push_back
#define MP make_pair
#define fr first
#define sc second
#define lli long long int
using namespace std;

const lli mod = 1000000009;
const int N = 3e5 + 20;
bool col[N];
int valid(int n, int inputSeq[])
{
  vector <int> a;
  for (int i = 0; i < n; i++) a.ad(inputSeq[i]);
  for (int i = 0; i < n; i++) a.ad(inputSeq[i]);
  int i1 = -1;
  for (int i = 0; i < n; i++)
  {
      if(col[a[i]]) return 0;
      col[a[i]] = true;
      if(a[i] <= n)
      {
          i1 = (i - a[i] + 1 + n) % n;
      }
  }
  if(i1 == -1) return 1;
  for (int i = i1; i < i1 + n; i++)
  {
      if(a[i] > n) continue;
      if(i - i1 + 1 != a[i]) return 0;
  }
  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  vector <int> a, pat;
  for (int i = 0; i < n; i++) a.ad(gondolaSeq[i]);
  for (int i = 0; i < n; i++) a.ad(gondolaSeq[i]);
  int i1 = 0;
  for (int i = 0; i < n; i++)
  {
      if(a[i] <= n)
          i1 = (i - a[i] + 1 + n) % n;
  }
  vector <pair<int, int> > fp;
  int nw = n + 1;
  for (int i = i1; i < i1 + n; i++)
  {
      fp.ad(MP(a[i], i - i1 + 1));
  }
  sort(fp.begin(), fp.end());
  for (int i = 0; i < fp.size(); i++)
  {
      while(nw <= fp[i].fr)
      {
          pat.ad(fp[i].sc);
          fp[i].sc = nw;
          nw++;
      }
  }
  for (int i = 0; i < pat.size(); i++) replacementSeq[i] = pat[i];
  return (int)pat.size();
}

lli bp(lli a, lli b = mod - 2LL)
{
    lli ret = 1;
    while(b)
    {
        if(b & 1) ret *= a, ret %= mod;
        a *= a, a %= mod;
        b >>= 1;
    }
    return ret;
}

int countReplacement(int n, int inputSeq[])
{
  vector <lli> fp;
  for (int i = 0; i < n; i++)
      if(inputSeq[i] > n) fp.ad(inputSeq[i]);
  lli nw = n + 1;
  lli m = fp.size();
  sort(fp.begin(), fp.end());
  lli pat = 1;
  if(m == n) pat = n;
  for (lli i = 0; i < m; i++)
  {
      //cout << i << endl;
      pat *= bp(m - i, fp[i] - nw);
      pat %= mod;
      nw = fp[i]+ 1;
  }
  return pat;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for (int i = 0; i < fp.size(); i++)
      |                   ~~^~~~~~~~~~~
gondola.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int i = 0; i < pat.size(); i++) replacementSeq[i] = pat[i];
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 7 ms 1148 KB Output is correct
7 Correct 15 ms 1784 KB Output is correct
8 Correct 12 ms 1784 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 14 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 7 ms 1148 KB Output is correct
7 Correct 15 ms 1784 KB Output is correct
8 Correct 12 ms 1784 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 14 ms 1872 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 7 ms 1148 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 16 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 17 ms 2804 KB Output is correct
12 Correct 18 ms 2932 KB Output is correct
13 Correct 24 ms 1784 KB Output is correct
14 Correct 16 ms 2804 KB Output is correct
15 Correct 26 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 18 ms 1276 KB Output is correct
10 Correct 15 ms 1276 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 20 ms 1276 KB Output is correct
10 Correct 14 ms 1148 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 10 ms 768 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 26 ms 2672 KB Output is correct
15 Correct 28 ms 2808 KB Output is correct
16 Correct 7 ms 1024 KB Output is correct
17 Correct 19 ms 1788 KB Output is correct
18 Correct 12 ms 1404 KB Output is correct