답안 #1071689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071689 2024-08-23T10:02:08 Z cpdreamer 곤돌라 (IOI14_gondola) C++14
55 / 100
12 ms 2616 KB
#include "gondola.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
using namespace std;
typedef long long ll;
#define V vector
#define F first
#define S second
#define P pair
#define pb push_back
#define all(v) v.begin(),v.end()
int valid(int n, int inputSeq[])
{
    int id=-1;
    for(int i=0;i<n;i++){
        if(inputSeq[i]==1) {
            id = i;
            break;
        }
    }
    if(id==-1)
        return 0;
    int c=2;
    for(int i=(id+1)%n;i!=id;i=(i+1)%n){
        if(inputSeq[i]!=c)
            return 0;
        c++;
    }
    return 1;
}
 
//----------------------
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    int id = -1, val;
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] <= n) {
            id = i;
            val = gondolaSeq[i];
            break;
        }
    }
    P<int, int> original[n];
    if (id != -1) {
        original[id].S = val;
        original[id].F = gondolaSeq[id];
        val=(val+1)%(n+1);
        if(val==0)
            val=1;
        for (int i = (id + 1) % n; i != id; i = (i + 1) % n) {
            original[i].S = val;
            original[i].F = gondolaSeq[i];
            val=(val+1)%(n+1);
            if(val==0)
                val=1;
        }
    } else {
        for (int i = 0; i < n; i++) {
            original[i].S = i + 1;
            original[i].F = gondolaSeq[i];
        }
    }
    int limit = n + 1;
    V<int> replace;
    sort(original, original + n);
    for (int i = 0; i < n; i++) {
        if (original[i].F != original[i].S) {
            replace.pb(original[i].S);
            for (int j = limit; j < original[i].F; j++) {
                replace.pb(j);
            }
            limit = original[i].F+1;
        }
    }
    for(int i=0;i<replace.size();i++){
        replacementSeq[i]=replace[i];
    }
    return (int)replace.size();
}
//----------------------
 
int countReplacement(int n, int inputSeq[]) {
    if(valid(n,inputSeq)==0)
        return 0;
    ll ans=1;
    ll mod=1e9+9;
    sort(inputSeq,inputSeq+n);
    for(int i=n+1;i<= *max_element(inputSeq,inputSeq+n)-1;i++){
        int l=0,r=n-1;
        int v=-1;
        while(l<=r){
            int m=l+(r-l)/2;
            if(inputSeq[m]>=i){
                v=m;
                r=m-1;
            }
            else{
                l=m+1;
            }
        }
        if(v!=-1) {
            if (inputSeq[v] != i) {
                ans = (ans * (n - v)) % mod;
            }
        }
    }
    if(*min_element(inputSeq,inputSeq+n)>n){
        ans=(ans*n)%mod;
    }
    ans=ans%mod;
    return (int)ans;
 }

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=0;i<replace.size();i++){
      |                 ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 6 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 5 ms 1116 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 6 ms 1116 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 820 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 6 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 448 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 9 ms 1628 KB Output is correct
12 Correct 9 ms 1884 KB Output is correct
13 Correct 10 ms 1748 KB Output is correct
14 Correct 7 ms 1628 KB Output is correct
15 Correct 12 ms 2616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -