답안 #1011516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011516 2024-06-30T14:37:39 Z SonicML 곤돌라 (IOI14_gondola) C++14
60 / 100
10 ms 2264 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include "gondola.h"

using namespace std;

int const NMAX = 1e5;
int const MMAX = 250000; 
int freq[1 + MMAX];

int valid(int n, int inputSeq[]) {
  int minpos = 0;
  bool isUnbroken = false;
  for(int i = 0;i < n;i++) {
    freq[inputSeq[i]]++;
    if(inputSeq[i] <= n) {
      isUnbroken = true;
      if(inputSeq[minpos] > inputSeq[i]) {
        minpos = i;
      }
    }
  }
  for(int i = 1;i <= MMAX;i++) {
    if(freq[i] > 1) {
      return 0;
    }
  }
  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 arr[1 + NMAX];

void printArr(int n) {
  for(int i = 0;i < n;i++) {
    cout << arr[i] << ' ';
  }
  cout << '\n';
  return;
}

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;
   }
 }
 //printArr(n);
 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];
  }
  if(!isUnbroken) {
    ans = (1LL * ans * n) % MODULO;
  }
  return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:144:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |   for(int i = 0;i < toMark.size();i++) {
      |                 ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 708 KB Output is correct
7 Correct 10 ms 1628 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 8 ms 1396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 6 ms 1484 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 6 ms 1372 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 9 ms 1636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Incorrect 1 ms 1372 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 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 1372 KB Output is correct
6 Correct 1 ms 1516 KB Output is correct
7 Incorrect 1 ms 1372 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 344 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 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 428 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 10 ms 2264 KB Output is correct
10 Correct 8 ms 1884 KB Output is correct
11 Correct 3 ms 1460 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 460 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 10 ms 2224 KB Output is correct
10 Correct 8 ms 1884 KB Output is correct
11 Correct 4 ms 1372 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 1 ms 688 KB Output is correct
14 Runtime error 7 ms 1816 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -