Submission #250686

#TimeUsernameProblemLanguageResultExecution timeMemory
250686hhh07Gondola (IOI14_gondola)C++14
100 / 100
30 ms2804 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <cmath>
#include <climits>
#include <cstring>
#include <stdio.h>
#include <assert.h>
#include "gondola.h"
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;

ll MOD = 1e9 + 9;

ll stepen(ll x, int st){
    ll res = 1;
    while(st > 0){
        if (st&1)
            res = (1LL)*(res*x)%MOD;
        x = (1LL)*(x*x)%MOD;
        st /= 2;
    }
    return res;
}

int valid(int n, int x[]){
    int j = -1;
    for (int i = 0; i < n; i++){
        if (x[i] > n)
            continue;
        j = i;
        break;
    }
    for (int i = 0; i < n; i++){
        if (j > i){
            int moze = x[j] - (j - i);
            if (moze < 1)
                moze += n;
            if (x[i] <= n && moze != x[i]){
                return false;
            }
        }
        else{
            int moze = x[j] + (i - j);
            if (moze > n)
                moze -= n;
            if (x[i] <= n && moze != x[i]){
                return false;
            }
        }
    }
    sort(x, x + n);
    for (int i = 1; i < n; i++)
        if (x[i] == x[i - 1])
            return false;
    return true;
}

int replacement(int n, int x[], int y[]){
    vector<ii> t;
    int j = 0;
    for (int i = 0; i < n; i++){
        if (x[i] > n)
            t.push_back(make_pair(x[i], i));
        else
            j = i;
    }
    
    sort(t.begin(), t.end());
    if (t.size() == n)
        x[0] = 1;
    for (int i = 0; i < n; i++){
        if (j > i){
            int moze = x[j] - (j - i);
            if (moze < 1)
                moze += n;
            x[i] = moze;
        }
        else{
            int moze = x[j] + (i - j);
            if (moze > n)
                moze -= n;
            x[i] = moze;
        }
    }
    vi res;
    int k = n;
    for (int i = 0; i < t.size(); i++){
        int curr = t[i].first, idx = t[i].second;
        res.push_back(x[idx]);
        for (int j = k + 1; j < curr; j++)
            res.push_back(j);
        k = curr;
    }
    for (int i = 0; i < res.size(); i++)
        y[i] = res[i];
    return res.size();
}


int countReplacement(int n, int x[]){
    bool k = valid(n, x);
    if (!k)
        return 0;
    vi t;
    for (int i = 0; i < n; i++)
        if (x[i] > n)
            t.push_back(x[i]);

    sort(t.begin(), t.end());
    ll res = 1;
    int prev = n;
    for (int i = 0; i < t.size(); i++){
        res *= stepen(t.size() - i, t[i] - prev - 1);
        res = res%MOD;
        prev = t[i];
    }
    if (t.size() == n){
        res *= n;
        res = res%MOD;
    }
    return res;
}

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:77:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (t.size() == n)
         ~~~~~~~~~^~~~
gondola.cpp:95:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < t.size(); i++){
                     ~~^~~~~~~~~~
gondola.cpp:102:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < res.size(); i++)
                     ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:120:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < t.size(); i++){
                     ~~^~~~~~~~~~
gondola.cpp:125:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (t.size() == n){
         ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...