제출 #734965

#제출 시각아이디문제언어결과실행 시간메모리
734965sandry24곤돌라 (IOI14_gondola)C++17
60 / 100
17 ms2240 KiB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second


#include "gondola.h"

map<int, int> freq;

int valid(int n, int inputSeq[])
{
  int i,j;
  for(i=0;i<n;i++)if(inputSeq[i]<=n)break;
  if(i<n)for(j=0;j<n;j++)if(inputSeq[j]<=n&&(inputSeq[j]+i)%n!=(inputSeq[i]+j)%n)return 0;
  std::sort(inputSeq,inputSeq+n);
  for(i=1;i<n;i++)if(inputSeq[i-1]==inputSeq[i])return 0;
  return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int index = -1, cnt = 0, next;
    for(int i = 0; i < n; i++)
        if(gondolaSeq[i] <= n)
            index = i;
    if(index == -1){
        index = 0;
        next = 1;
    } else next = gondolaSeq[index];
    vector<pi> temp;
    int current = n+1;
    while(cnt != n){
        if(gondolaSeq[index] != next)
            temp.pb({gondolaSeq[index], next});
        index = (index == n-1 ? 0 : index + 1);
        next = (next == n ? 1 : next + 1);
        cnt++;
    }
    sort(temp.begin(), temp.end());
    int ind = 0;
    for(int i = 0; i < temp.size(); i++){
        while(temp[i].f != temp[i].s){
            replacementSeq[ind] = temp[i].s;
            temp[i].s = current;
            current++;
            ind++;
        }
    }
    return ind;
}

ll bin_pow(ll a, ll b, ll mod){
    ll ans = 1;
    while(b > 0){
        if(b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}

int countReplacement(int n, int inputSeq[]){
    if(!valid(n, inputSeq))
        return 0;
    vector<ll> temp;
    for(int i = 0; i < n; i++){
        if(inputSeq[i] > n){
            temp.pb(inputSeq[i]);
        }
    }
    ll ans = 1, mod = 1e9+7, current = n+1;
    sort(temp.begin(), temp.end());
    for(int i = 0; i < temp.size(); i++){
        ll diff = temp[i] - current;
        ans *= bin_pow((ll)temp.size() - i, diff, mod);
        ans %= mod;
        current = temp[i] + 1;
    }
    return (ans % mod);
}

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:49: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]
   49 |     for(int i = 0; i < temp.size(); i++){
      |                    ~~^~~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0; i < temp.size(); i++){
      |                    ~~^~~~~~~~~~~~~
#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...