Submission #795625

# Submission time Handle Problem Language Result Execution time Memory
795625 2023-07-27T11:49:18 Z AbdullahMohammedAhmad Minerals (JOI19_minerals) C++14
Compilation error
0 ms 0 KB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 43000;
constexpr int MAX_CALLS = 1000000;

namespace {

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

int N;
int counterpart[2 * MAX_N + 1];

int num_queries;
int num_kinds;
int on[2 * MAX_N + 1];
int cntt[2 * MAX_N + 1];

int num_answers;
int answer[2 * MAX_N + 1];

}  // namespace

int Query(int x) {
  if (!(1 <= x && x <= 2 * N)) {
    WrongAnswer(1);
  }
  if (++num_queries > MAX_CALLS) {
    WrongAnswer(2);
  }
  const int type = std::min(x, counterpart[x]);
  if (on[x]) {
    --on[x];
    --cntt[type];
    if (cntt[type] == 0) {
      --num_kinds;
    }
  } else {
    ++on[x];
    ++cntt[type];
    if (cntt[type] == 1) {
      ++num_kinds;
    }
  }
  return num_kinds;
}

void Answer(int a, int b) {
  if (++num_answers > N) {
    WrongAnswer(6);
  }
  if (!(1 <= a && a <= 2 * N && 1 <= b && b <= 2 * N)) {
    WrongAnswer(3);
  }
  if (answer[a] != 0) {
    WrongAnswer(4);
  }
  answer[a] = b;
  if (answer[b] != 0) {
    WrongAnswer(4);
  }
  answer[b] = a;
  if (!(counterpart[a] == b && counterpart[b] == a)) {
    WrongAnswer(5);
  }
}

deque<int> m;

void clear_queue()
{
    while(!m.empty())
    {
        Query(m.back());
        m.pop_back();
    }
    
}

void Solve(int N) {
    vector<vector<int>> prev1(1);
    vector<vector<int>> prev2(1);
    for(int i = 1; i <= 2*N; i++)
    {
        m.push_back(i);
        if(Query(i) != m.size())
        {
            prev2[0].push_back(i);
            Query(i);
            m.pop_back();
        }
        else
        {
            prev1[0].push_back(i);
        }
    }
    clear_queue();
    while(prev1.size() < N)
    {
        vector<vector<int>> now1;
        vector<vector<int>> now2;
        for(int i = 0; i < prev1.size(); i++)
        {
            //ONE
            if(prev1[i].size() == 1)
            {
                now1.push_back(prev1[i]);
                now2.push_back(prev2[i]);
                continue;
            }
            now1.push_back(vector<int>());
            now1.push_back(vector<int>());
            now2.push_back(vector<int>());
            now2.push_back(vector<int>());
            for(int j = 0; j < prev1[i].size(); j++)
            {
                if(j%2 == 0)
                {
                    now1[now1.size()-2].push_back(prev1[i][j]);
                    m.push_back(prev1[i][j]);
                    Query(prev1[i][j]);
                }
                else
                {
                    now1[now1.size()-1].push_back(prev1[i][j]);
                }
            }
            for(int j = 0; j < prev2[i].size(); j++)
            {
                m.push_back(prev2[i][j]);
                if(Query(prev2[i][j]) == m.size())
                {
                    now2[now2.size()-1].push_back(prev2[i][j]);
                    Query(prev2[i][j]);
                    m.pop_back();
                }
                else
                {
                    now2[now2.size()-2].push_back(prev2[i][j]);
                    Query(prev2[i][j]);
                    m.pop_back();
                }
            }
            clear_queue();
        }
        prev1 = now1;
        prev2 = now2;
    }
    for(int i = 0; i < N; i++)
    {
        Answer(prev1[i][0], prev2[i][0]);
    }
}

int main() {
  if (scanf("%d", &N) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  for (int i = 1; i <= N; ++i) {
    int x, y;
    if (scanf("%d%d", &x, &y) != 2) {
      fprintf(stderr, "Error while reading input\n");
      exit(1);
    }
    counterpart[x] = y;
    counterpart[y] = x;
  }
  Solve(N);
  if (num_answers != N) {
    WrongAnswer(6);
  }
  printf("Accepted: %d\n", num_queries);
  return 0;
}

/*
4
1 5
2 6
3 4
7 8
 */

Compilation message

minerals.cpp: In function 'void Solve(int)':
minerals.cpp:91:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         if(Query(i) != m.size())
      |            ~~~~~~~~~^~~~~~~~~~~
minerals.cpp:103:24: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  103 |     while(prev1.size() < N)
      |           ~~~~~~~~~~~~~^~~
minerals.cpp:107:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |         for(int i = 0; i < prev1.size(); i++)
      |                        ~~^~~~~~~~~~~~~~
minerals.cpp:120:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |             for(int j = 0; j < prev1[i].size(); j++)
      |                            ~~^~~~~~~~~~~~~~~~~
minerals.cpp:133:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |             for(int j = 0; j < prev2[i].size(); j++)
      |                            ~~^~~~~~~~~~~~~~~~~
minerals.cpp:136:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |                 if(Query(prev2[i][j]) == m.size())
      |                    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccvc01cm.o: in function `Query(int)':
grader.cpp:(.text+0x30): multiple definition of `Query(int)'; /tmp/ccC3CJ3n.o:minerals.cpp:(.text+0x180): first defined here
/usr/bin/ld: /tmp/ccvc01cm.o: in function `Answer(int, int)':
grader.cpp:(.text+0x100): multiple definition of `Answer(int, int)'; /tmp/ccC3CJ3n.o:minerals.cpp:(.text+0x250): first defined here
/usr/bin/ld: /tmp/ccvc01cm.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccC3CJ3n.o:minerals.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status