제출 #1072347

#제출 시각아이디문제언어결과실행 시간메모리
1072347duckindogArt Collections (BOI22_art)C++17
50 / 100
488 ms1376 KiB
#include <bits/stdc++.h>
 
#ifndef LOCAL
#include "art.h"
#endif
 
using namespace std;
 
void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...) {
    va_list args;
    va_start(args, msg);
    vfprintf(stdout, msg, args);
    fprintf(stdout, "\n");
    va_end(args);
    exit(0);
}
 
#ifdef LOCAL
namespace {
    int N;
    int Q = 0;
    const int MAX_Q = 4000;
    const int MAX_N = 4000;
    vector<int> solution;
}  // namespace
 
int publish(vector<int> R) {
    printf("publish({");
    for(int i = 0; i < int(R.size()); ++i) {
        if(i == 0)
            printf("%d", R[i]);
        else
            printf(", %d", R[i]);
    }
    printf("})\n");
    fflush(stdout);
 
    if (++Q > MAX_Q)
        result("Too many published rankings!");
 
    if (int(R.size()) != N)
        result("Invalid published ranking!");
 
    set<int> chosen;
    for(auto &x : R) {
        if(x < 1 || x > N || chosen.count(x))
            result("Invalid published ranking!");
        chosen.insert(x);
    }
    vector<int> positions(N+1);
    for(int i = 0; i < N; ++i)
        positions[R[i]] = i;
 
    int complaints = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N; ++j) {
            if(positions[solution[i]] > positions[solution[j]])
                ++complaints;
        }
    }
 
    return complaints;
}
 
void __attribute__((noreturn)) answer(vector<int> R) {
    printf("answer({");
    for(int i = 0; i < int(R.size()); ++i) {
        if(i == 0)
            printf("%d", R[i]);
        else
            printf(", %d", R[i]);
    }
    printf("})\n");
    fflush(stdout);
 
 
    if(R == solution)
        result("Correct: %d published ranking(s).", Q);
    else
        result("Wrong answer!");
}
#endif
 
vector<int> order;
int x;
bool cmp (const auto& a, const auto& b) { 
  swap(order[a - 1], order[b - 1]);
  int y = publish(order);
  swap(order[a - 1], order[b - 1]);
  return (a > b ? x > y : x < y);
};


vector<int> mergeSort(vector<int> vt) { 
  if (vt.size() <= 1) return vt;
  vector<int> a(vt.begin(), vt.begin() + vt.size() / 2),
              b(vt.begin() + vt.size() / 2, vt.end());
  a = mergeSort(a); b = mergeSort(b);
  if (b.size() && !cmp(a[0], b[0])) swap(a, b);
  vector<vector<int>> save(a.size());

  int it = 0;
  for (const auto& x : b) { 
    while (it + 1 < a.size() && cmp(a[it + 1], x)) it += 1;
    save[it].push_back(x);
  }

  vector<int> ret;
  for (int i = 0; i < a.size(); ++i) { 
    ret.push_back(a[i]);
    for (const auto&x : save[i]) ret.push_back(x);
  }
  return ret;
}

void solve(int n) {
  order.resize(n); iota(order.begin(), order.end(), 1);
  x = publish(order);
  auto ret = mergeSort(order);

  answer(ret);
}
 
#ifdef LOCAL
int main() {
    if (scanf("%d", &N) != 1 || N < 2 || N > MAX_N)
        result("Invalid input!");
 
    solution.resize(N);
    set<int> chosen;
    for(auto &x : solution) {
        if(scanf("%d", &x) != 1 || x < 1 || x > N || chosen.count(x))
            result("Invalid input!");
        chosen.insert(x);
    }
 
    solve(N);
 
    result("No answer!");
}
#endif

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

art.cpp:86:17: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   86 | bool cmp (const auto& a, const auto& b) {
      |                 ^~~~
art.cpp:86:32: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   86 | bool cmp (const auto& a, const auto& b) {
      |                                ^~~~
art.cpp: In function 'std::vector<int> mergeSort(std::vector<int>)':
art.cpp:104:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     while (it + 1 < a.size() && cmp(a[it + 1], x)) it += 1;
      |            ~~~~~~~^~~~~~~~~~
art.cpp:109:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |   for (int i = 0; i < a.size(); ++i) {
      |                   ~~^~~~~~~~~~
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
#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...