Submission #131420

# Submission time Handle Problem Language Result Execution time Memory
131420 2019-07-17T06:52:41 Z DodgeBallMan Gondola (IOI14_gondola) C++14
100 / 100
56 ms 4480 KB
#include <bits/stdc++.h>/
#include "gondola.h"
#define pii pair<int, int>
#define x first
#define y second

using namespace std;

long long mod = 1e9 + 9;

int valid( int n, int num[] ) {
    unordered_map<int,int> m;
    int st = 0;
    for( int i = 0 ; i < n ; i++ ) {
        if( m[num[i]] > 0 ) return 0;
        if( num[i] <= n && st == 0 ) st = num[i];
        else if( num[i] <= n && st > 0 && st != num[i] ) return 0; 
        if( st != 0 ) st = ( st % n ) + 1; 
        m[num[i]]++;
    }
    return 1;
}

int replacement( int n, int num[], int se[] ) {
    vector<pii> all;
    int ori[250100];
    memset( ori, -1, sizeof ori );
    for( int i = 0 ; i < n ; i++ ) if( num[i] <= n ) {
        ori[i] = num[i] - 1;
        for( int j = i + 1 ; j < n ; j++ ) ori[j] = ( num[i] - 1 + j - i ) % n;
        for( int j = i - 1 ; j >= 0 ; j-- ) ori[j] = ( num[i] - 1 + n + j - i ) % n;
        break;
    }
    if( ori[0] == -1 ) for( int i = 0 ; i < n ; i++ ) ori[i] = i;
    for( int i = 0 ; i < n ; i++ ) ori[i]++;
    for( int i = 0 ; i < n ; i++ ) if( num[i] > n ) all.emplace_back( pii( num[i], ori[i] ) );
    sort( all.begin(), all.end() );
    int cnt = 0, fix = n + 1;
    for( int i = 0 ; i < all.size() ; i++ ) {
        int a, b;
        tie( a, b ) = all[i];
        while( b != a ) {
            se[cnt] = b;
            b = fix;
            cnt++, fix++;
        }
    }
    return cnt;
}

long long modpow( long long base, long long power ) {
    long long ret = 1;
    for( ; power ; power >>= 1) {
        if( power & 1 ) ret = ( ret * base ) % mod;
        base = ( base * base ) % mod;
    }
    return ret;
}
int countReplacement( int n, int num[] ) {
    vector<int> all;
    if( !valid( n, num ) ) return 0;
    for( int i = 0 ; i < n ; i++ ) if( num[i] > n ) all.emplace_back( num[i] );
    sort( all.begin(), all.end() );
    int now = n + 1;
    long long ret = 1;
    for( int i = 0 ; i < ( int )all.size() ; i++ ) {
        ret = ( ret * modpow( ( int )all.size() - i, all[i] - now ) ) % mod;
        now = all[i] + 1;
    }
    if( ( int )all.size() == n ) ret = ( ret * n ) % mod;
    return ( int )ret;
}

// int main() {
//     int n, se[100], num[100];
//     scanf("%d",&n);
//     for( int i = 0 ; i < n ; i++ ) scanf("%d",&num[i]);
//     int x = countReplacement( n, num );
//     printf("%d\n",x);
// }

Compilation message

gondola.cpp:1:25: warning: extra tokens at end of #include directive
 #include <bits/stdc++.h>/
                         ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:39:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < all.size() ; i++ ) {
                      ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 13 ms 2088 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 23 ms 3720 KB Output is correct
9 Correct 9 ms 1400 KB Output is correct
10 Correct 25 ms 4100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 13 ms 2088 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 23 ms 3764 KB Output is correct
9 Correct 8 ms 1400 KB Output is correct
10 Correct 25 ms 4104 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 14 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 3 ms 1272 KB Output is correct
9 Correct 4 ms 1400 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1272 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 12 ms 1528 KB Output is correct
12 Correct 14 ms 1656 KB Output is correct
13 Correct 18 ms 2328 KB Output is correct
14 Correct 12 ms 1656 KB Output is correct
15 Correct 24 ms 3300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 40 ms 3724 KB Output is correct
10 Correct 33 ms 3496 KB Output is correct
11 Correct 13 ms 1400 KB Output is correct
12 Correct 17 ms 1912 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 38 ms 3716 KB Output is correct
10 Correct 32 ms 3496 KB Output is correct
11 Correct 13 ms 1272 KB Output is correct
12 Correct 17 ms 1912 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 56 ms 4100 KB Output is correct
15 Correct 56 ms 4480 KB Output is correct
16 Correct 11 ms 1140 KB Output is correct
17 Correct 38 ms 3544 KB Output is correct
18 Correct 22 ms 1960 KB Output is correct