답안 #1011406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011406 2024-06-30T13:13:34 Z SonicML 곤돌라 (IOI14_gondola) C++14
35 / 100
12 ms 1496 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include "gondola.h"

using namespace std;

int valid(int n, int inputSeq[]) {
  int minpos = 0;
  bool isUnbroken = false;
  for(int i = 0;i < n;i++) {
    if(inputSeq[i] <= n) {
      isUnbroken = true;
      if(inputSeq[minpos] > inputSeq[i]) {
        minpos = i;
      }
    }
  }
  if(isUnbroken) {
    for(int i = 0;i < n;i++) {
      if(inputSeq[i] <= n) {
        int distPos = (n + i - minpos) % n;
        int distVal = inputSeq[i] - inputSeq[minpos];
        if(distPos != distVal) {
          return 0;
        }
      }
    }
  }
  return 1;
}

int const NMAX = 1e5;
int const MMAX = 250000;

int arr[1 + NMAX];

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
 bool unmarked[1 + NMAX];
 int pos[1 + MMAX];
 int maxx = 0, minpos = 0;
 bool isUnbroken = false;
 for(int i = 1;i <= MMAX;i++) {
   pos[i] = -1;
 }
 for(int i = 0;i < n;i++) {
   if(gondolaSeq[i] <= n) {
     unmarked[i] = false;
     isUnbroken = true;
     if(gondolaSeq[minpos] > gondolaSeq[i]) {
       minpos = i;
     }
   } else {
     unmarked[i] = true;
   }
   pos[gondolaSeq[i]] = i;
   maxx = max(maxx, gondolaSeq[i]);
 }
 if(isUnbroken) {
   for(int i = 0;i < n;i++) {
     int dist = (n + i - minpos);
     int val = (gondolaSeq[minpos] + dist) % n;
     if(val == 0) {
       val = n;
     }
     arr[i] = val;
   }
 }else {
   for(int i = 0;i < n;i++) {
     arr[i] = i + 1;
   }
 }
 int dump = 0, index = 0;
 for(int i = n+1;i <= maxx;i++) {
   if(pos[i] == -1) {
     while(unmarked[dump]) {
       dump++;
     }
     replacementSeq[index] = arr[dump];
     arr[dump] = i;
     index++;
   }else {
     replacementSeq[index] = arr[pos[i]];
     arr[pos[i]] = i;
     index++;
   }
 }
 return index;
}

int const MODULO = 1e9+9;

int logPow(int a, int b) {
  if(b == 0) {
    return 1;
  } else if(b == 1) {
    return a;
  } else {
    int mult = logPow(a, b/2);
    mult = (1LL * mult * mult) % MODULO;
    if(b % 2 == 1) {
      return (1LL * mult * a) % MODULO;
    } else {
      return mult;
    }
  }
}

int countReplacement(int n, int inputSeq[]) {
  if(!valid(n, inputSeq)) {
    //cerr << "SUDOKU\n";
    return 0;
  }
  vector <int> toMark;
  int unmarked = n;
  bool isUnbroken = false;
  for(int i = 0;i < n;i++) {
    if(inputSeq[i] <= n) {
      unmarked--;  
      isUnbroken = true;
    } else {
      toMark.push_back(inputSeq[i]);
    }
  }
  sort(toMark.begin(), toMark.end());
  int prev = n, ans = 1;

  for(int i = 0;i < toMark.size();i++) {
    int dist = (toMark[i] - prev - 1);
    //cerr << unmarked << ' ' << logPow(unmarked, dist) << '\n';
    ans = (1LL * ans * logPow(unmarked, dist)) % MODULO;
    unmarked--;
    prev = toMark[i];
  }
  return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:128:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |   for(int i = 0;i < toMark.size();i++) {
      |                 ~~^~~~~~~~~~~~~~~
gondola.cpp:116:8: warning: variable 'isUnbroken' set but not used [-Wunused-but-set-variable]
  116 |   bool isUnbroken = false;
      |        ^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 444 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 3 ms 756 KB Output is correct
7 Correct 12 ms 1116 KB Output is correct
8 Correct 6 ms 1116 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 10 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 5 ms 1076 KB Output is correct
9 Correct 3 ms 576 KB Output is correct
10 Correct 10 ms 1092 KB Output is correct
11 Incorrect 0 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1464 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Incorrect 1 ms 1372 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 2 ms 1368 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1472 KB Output is correct
6 Incorrect 1 ms 1372 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 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 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 444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 9 ms 1484 KB Output is correct
10 Correct 8 ms 1372 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 4 ms 872 KB Output is correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 10 ms 1496 KB Output is correct
10 Correct 8 ms 1372 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -