답안 #278330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278330 2020-08-21T11:55:19 Z shinjan 곤돌라 (IOI14_gondola) C++14
75 / 100
65 ms 6520 KB
#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000009
#include "gondola.h"
using namespace std;
set<int> gond;
set<int> pok;
/*long long step(int a,int b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%mod;
    if(b%2==0)
        return (step(a,b/2)%mod)*(step(a,b/2)%mod);
    return (step(a,b/2)%mod)*(step(a,b/2)%mod)*(a%mod);
}*/
int valid(int n,int seq[])
{
    int prvi=-1;
    for(int i=0;i<n;i++)
    {
        if(seq[i]<=n)
        {
            prvi=i;
            break;
        }
    }
    if(prvi==-1)
    {
        for(int i=0;i<n;i++)
        {
            if(gond.find(seq[i])!=gond.end())
            {
                return 0;
            }
            gond.insert(seq[i]);
        }
        return 1;
    }
    int tren=seq[prvi];
    for(int i=prvi+1;i<n;i++)
    {
        if(tren==n)
        {
            if(seq[i]!=1)
            {
                if(seq[i]<=n)
                {
                    return 0;
                }
                if(gond.find(seq[i])!=gond.end())
                {
                    return 0;
                }
                gond.insert(seq[i]);
            }
            tren=1;
        }
        else if(seq[i]!=tren+1)
        {
            if(seq[i]<=n)
            {
                return 0;
            }
            if(gond.find(seq[i])!=gond.end())
            {
                return 0;
            }
            gond.insert(seq[i]);
            tren=tren+1;
        }
        else{
            tren=tren+1;
        }
    }
    for(int i=0;i<=prvi;i++)
    {
        if(tren==n)
        {
            if(seq[i]!=1)
            {
                if(seq[i]<=n)
                {
                    return 0;
                }
                if(gond.find(seq[i])!=gond.end())
                {
                    return 0;
                }
                gond.insert(seq[i]);
            }
            tren=1;
        }
        else if(seq[i]!=tren+1)
        {
            if(seq[i]<=n)
            {
                return 0;
            }
            if(gond.find(seq[i])!=gond.end())
            {
                return 0;
            }
            gond.insert(seq[i]);
            tren=tren+1;
        }
        else{
            tren=tren+1;
        }
    }
    return 1;
}
int replacement(int n, int gondola[], int promena[])
{
    int prvi=-1;
    vector <pair<int,int>> v;
    for(int i=0;i<n;i++)
    {
        if(gondola[i]<=n)
        {
            prvi=i;
            break;
        }
    }
    if(prvi==-1)
    {
        for(int i=0;i<n;i++)
        {
            v.push_back({gondola[i],i+1});
        }
        sort(v.begin(),v.end());
        int tren=n+1;
        int poz=0;
        for(int i=0;i<v.size();i++)
        {
            promena[poz]=v[i].second;
            poz++;
            while(tren!=v[i].first)
            {
                promena[poz]=tren;
                poz++;
                tren++;
            }
            tren++;
        }
        return poz;
    }
    int next;
    if(gondola[prvi]==n)
    {
        next=1;
    }
    else{
        next=gondola[prvi]+1;
    }
    for(int i=prvi+1;i<n;i++)
    {
        if(gondola[i]!=next)
        {
            v.push_back({gondola[i],next});
        }
        if(next==n)
        {
            next=1;
        }
        else{
            next++;
        }
    }
    for(int i=0;i<prvi;i++)
    {
        if(gondola[i]!=next)
        {
            v.push_back({gondola[i],next});
        }
        if(next==n)
        {
            next=1;
        }
        else{
            next++;
        }
    }
    sort(v.begin(),v.end());
    int tren=n+1;
    int poz=0;
    for(int i=0;i<v.size();i++)
    {
        promena[poz]=v[i].second;
        poz++;
        while(tren!=v[i].first)
        {
            promena[poz]=tren;
            poz++;
            tren++;
        }
        tren++;
    }
    return poz;
}
int countReplacement(int n, int seq[])
{
    if(!valid(n,seq))
        return 0;
    int brpok=0;
    int maks=0;
    for(int i=0;i<n;i++)
    {
        if(seq[i]>n)
        {
            brpok++;
            pok.insert(seq[i]);
        }
        maks=max(maks,seq[i]);
    }
    if(brpok==0)
        return 1;
    int stepen=0;
    int ans=1;
    long long suma=1;
    for(int i=n+1;i<=maks;i++)
    {
        if(pok.find(i)!=pok.end())
        {
            brpok--;
        }
        else{
            suma=(suma%mod)*(brpok%mod);
            suma=(suma%mod);
            //ans=suma;
        }
    }
    suma=(suma%mod);
    ans=suma;
    return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:135: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]
  135 |         for(int i=0;i<v.size();i++)
      |                     ~^~~~~~~~~
gondola.cpp:188:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  188 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:219:9: warning: unused variable 'stepen' [-Wunused-variable]
  219 |     int stepen=0;
      |         ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 16 ms 640 KB Output is correct
8 Correct 10 ms 640 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 10 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 11 ms 640 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 11 ms 640 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 13 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 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 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 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 256 KB Output is correct
6 Correct 0 ms 256 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 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 10 ms 640 KB Output is correct
12 Correct 11 ms 640 KB Output is correct
13 Correct 17 ms 1296 KB Output is correct
14 Correct 10 ms 640 KB Output is correct
15 Correct 28 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 63 ms 6520 KB Output is correct
10 Correct 49 ms 4984 KB Output is correct
11 Correct 25 ms 2688 KB Output is correct
12 Correct 26 ms 3072 KB Output is correct
13 Incorrect 10 ms 1032 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 65 ms 6520 KB Output is correct
10 Correct 46 ms 4984 KB Output is correct
11 Correct 23 ms 2688 KB Output is correct
12 Correct 27 ms 3072 KB Output is correct
13 Incorrect 10 ms 1024 KB Output isn't correct
14 Halted 0 ms 0 KB -