Submission #396844

# Submission time Handle Problem Language Result Execution time Memory
396844 2021-04-30T19:39:19 Z ly20 Gondola (IOI14_gondola) C++17
100 / 100
82 ms 5088 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 9;
int valid(int n, int seq[])
{
    bool vl = true;
    int id0 = n;
    map <int, int> freq;
    for(int i = 0; i < n; i++) {
        freq[seq[i]]++;
        if(freq[seq[i]] > 1) vl = false;
        if(seq[i] > n) continue;
        if(id0 == n) {
            id0 = (seq[i] - i + n) % n;
        }
        else {
            if(id0 != (seq[i] - i + n) % n) vl = false;
        }
    }
    if(vl) return 1;
    else return 0;
}

//----------------------
int vor[112345];
int replacement(int n, int seq[], int resp[])
{
    int ch = 0;
    for(int i = 0; i < n; i++) {
        if(seq[i] <= n && ch == 0) {
            ch = 1;
            int at = i;
            int cur = seq[i] - 1;
            while(vor[at] == 0) {
                vor[at] = cur + 1;
                cur++;
                at++;
                cur %= n;
                at %= n;
            }
        }
    }
    if(ch == 0) {
        for(int i = 0; i < n; i++) {
            vor[i] = i + 1;
        }
    }
    vector <pair <int, int> > mx;
    for(int i = 0; i < n; i++) {
        if(seq[i] > n) mx.push_back(make_pair(seq[i], i));
    }
    sort(mx.begin(), mx.end());
    int fim = n + 1;
    vector <int> rs;
    for(int i = 0; i < mx.size(); i++) {
        while(fim <= mx[i].first) {
            int id = mx[i].second;
            rs.push_back(vor[id]);
            vor[id] = fim;
            fim++;
        }
    }
    for(int i = 0; i < rs.size(); i++) {
        resp[i] = rs[i];
    }
    return rs.size();
}

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

long long fexp(long long n, int t) {
    long long at = 1;
    for(int i = 31; i >= 0; i--) {
        at = at * at;
        at %= MOD;
        if((1 << i) & t) {
            at *= n;
            at %= MOD;
        }
    }
    return at;
}
int countReplacement(int n, int seq[])
{
    if(!valid(n, seq)) return 0;
    long long resp = 1;
    vector <int> rp;
    for(int i = 0; i < n; i++) {
        if(seq[i] > n) rp.push_back(seq[i]);
    }
    int av = rp.size();
    int ls = n + 1;
    sort(rp.begin(), rp.end());
    for(int i = 0; i < rp.size(); i++) {
        //printf("%d %d %d\n", rp[i], ls, av);
        resp = resp * fexp(av, rp[i] - ls);
        //  printf("%lld\n", fexp(rp[i] - ls, av));
        resp %= MOD;
        av--;
        ls = rp[i] + 1;
    }
    if(rp.size() == n) resp = (resp * n) % MOD;
    return resp;
}
/*int v[1123456];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	printf("%d\n",countReplacement(n,v));
	return 0;
}
*/

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i = 0; i < mx.size(); i++) {
      |                    ~~^~~~~~~~~~~
gondola.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i < rs.size(); i++) {
      |                    ~~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i = 0; i < rp.size(); i++) {
      |                    ~~^~~~~~~~~~~
gondola.cpp:103:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  103 |     if(rp.size() == n) resp = (resp * n) % MOD;
      |        ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 14 ms 2124 KB Output is correct
7 Correct 38 ms 3724 KB Output is correct
8 Correct 32 ms 3832 KB Output is correct
9 Correct 8 ms 1356 KB Output is correct
10 Correct 34 ms 4452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 15 ms 2152 KB Output is correct
7 Correct 38 ms 3616 KB Output is correct
8 Correct 29 ms 3916 KB Output is correct
9 Correct 9 ms 1380 KB Output is correct
10 Correct 35 ms 4468 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 19 ms 2056 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 48 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 11 ms 840 KB Output is correct
12 Correct 14 ms 912 KB Output is correct
13 Correct 17 ms 1480 KB Output is correct
14 Correct 11 ms 844 KB Output is correct
15 Correct 26 ms 2332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 56 ms 3928 KB Output is correct
10 Correct 43 ms 3312 KB Output is correct
11 Correct 17 ms 1356 KB Output is correct
12 Correct 20 ms 1612 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 55 ms 4020 KB Output is correct
10 Correct 43 ms 3384 KB Output is correct
11 Correct 17 ms 1440 KB Output is correct
12 Correct 22 ms 1692 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 70 ms 4508 KB Output is correct
15 Correct 82 ms 5088 KB Output is correct
16 Correct 13 ms 1100 KB Output is correct
17 Correct 52 ms 3532 KB Output is correct
18 Correct 28 ms 2140 KB Output is correct