제출 #737772

#제출 시각아이디문제언어결과실행 시간메모리
737772DeepessonSuper Dango Maker (JOI22_dango3)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
///#include "dango3.h"

void Answer(const std::vector<int> &a);
int Query(const std::vector<int> &x);

std::vector<int> concatena(std::vector<int> a,std::vector<int> b){
    for(auto&x:b)a.push_back(x);
    return a;
}
void Solve(int N, int M) {
    int tot = N*M;
    bool foi[tot]={};
    for(int i=0;i!=M;++i){
        std::vector<int> base;
        while(base.size()!=N){
            int l=0,r=N*M-1;
            while(l<r){
                int m = (l+r)/2;
                std::vector<int> add;
                for(int j=0;j<=m;++j){
                    if(!foi[j])add.push_back(j+1);
                }
                if(Query(concatena(add,base))>=1){
                    r=m;
                }else l=m+1;
            }
            base.push_back(l+1);
            foi[l]=1;
        }
        Answer(base);
    }
}


namespace {

using std::exit;
using std::fprintf;
using std::printf;
using std::scanf;

constexpr int Q_MAX = 50'000;
constexpr int NM_MAX = 10'000;

int N;
int M;
int C[NM_MAX + 1];

int query_count = 0;
int answer_count = 0;
bool finishes[NM_MAX + 1];

void WrongAnswer(int code) {
  printf("Wrong Answer [%d]\n", code);
  exit(0);
}
}  // namespace

int Query(const std::vector<int> &x) {
  if (++query_count > Q_MAX) WrongAnswer(3);
  bool presents[NM_MAX + 1];
  for (int i = 1; i <= N * M; ++i) presents[i] = false;
  int colors[NM_MAX + 1];
  for (int i = 1; i <= N; i++) colors[i] = 0;
  for (const int t : x) {
    if (t <= 0 || t > N * M) WrongAnswer(1);
    if (presents[t]) WrongAnswer(2);
    presents[t] = true;
    colors[C[t]]++;
  }
  int color_min = M;
  for (int i = 1; i <= N; i++) {
    if (colors[i] < color_min) color_min = colors[i];
  }
  return color_min;
}

void Answer(const std::vector<int> &a) {
  ++answer_count;
  if ((int)a.size() != N) WrongAnswer(4);
  for (const int t : a) {
    if (t <= 0 || t > N * M) WrongAnswer(5);
    if (finishes[t]) WrongAnswer(6);
    finishes[t] = true;
  }
  int colors[NM_MAX + 1];
  for (int i = 1; i <= N; i++) colors[i] = 0;
  for (const int t : a) {
    colors[C[t]]++;
  }
  for (int i = 1; i <= N; i++) {
    if (colors[i] != 1) WrongAnswer(7);
  }
}

int main() {
  if (scanf("%d%d", &N, &M) != 2) {
    fprintf(stderr, "Error while reading input.\n");
    exit(1);
  }
  for (int i = 1; i <= N * M; ++i) {
    if (scanf("%d", &C[i]) != 1) {
      fprintf(stderr, "Error while reading input.\n");
      exit(1);
    }
  }
  for (int i = 1; i <= N * M; ++i) finishes[i] = false;
  Solve(N, M);
  if (answer_count != M) WrongAnswer(8);
  printf("Accepted: %d\n", query_count);
  return 0;
}

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

dango3.cpp: In function 'void Solve(int, int)':
dango3.cpp:16:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |         while(base.size()!=N){
      |               ~~~~~~~~~~~^~~
/usr/bin/ld: /tmp/ccHQ1cHs.o: in function `Query(std::vector<int, std::allocator<int> > const&)':
grader.cpp:(.text+0x50): multiple definition of `Query(std::vector<int, std::allocator<int> > const&)'; /tmp/ccu4Gwct.o:dango3.cpp:(.text+0x170): first defined here
/usr/bin/ld: /tmp/ccHQ1cHs.o: in function `Answer(std::vector<int, std::allocator<int> > const&)':
grader.cpp:(.text+0x1c0): multiple definition of `Answer(std::vector<int, std::allocator<int> > const&)'; /tmp/ccu4Gwct.o:dango3.cpp:(.text+0x1a0): first defined here
/usr/bin/ld: /tmp/ccHQ1cHs.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccu4Gwct.o:dango3.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status