제출 #1171800

#제출 시각아이디문제언어결과실행 시간메모리
1171800IskachunArt Collections (BOI22_art)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <set>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "art.h"/*
using namespace std;
typedef long long ll;
namespace {
    int N;
    int Q = 0;
    const int MAX_Q = 4000;
    const int MAX_N = 4000;
    vector<int> solution;
}
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);
}
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!");
}
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 solve(int n) {
    vector<int> ans(n);
    for (int i = 1; i <= n; i++) ans[i - 1] = i;
    int x = publish(ans);
    while (x) {
        for (int i = 1; i < n; i++) {
            vector<int> curr = ans;
            swap(curr[i], curr[i - 1]);
            int y = publish(curr);
            if (y < x) ans = curr, i++, x = y;
        }
    }
    answer(ans);
    /// use of functions
    /*std::vector<int> order = {1, 2, 3};
    publish(order);
    order = {2, 3, 1};
    publish(order);
    order = {1, 3, 2};
    answer(order);*/
}/*
int main() {
    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);
    //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //int t = 1; //cin >> t;
    //while (t--) solve();
    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!");
}
*/

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

art.cpp: In function 'void solve(int)':
art.cpp:80:5: error: 'vector' was not declared in this scope
   80 |     vector<int> ans(n);
      |     ^~~~~~
art.cpp:80:5: note: suggested alternatives:
In file included from /usr/include/c++/11/vector:67,
                 from art.cpp:2:
/usr/include/c++/11/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from art.cpp:2:
/usr/include/c++/11/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
art.cpp:80:12: error: expected primary-expression before 'int'
   80 |     vector<int> ans(n);
      |            ^~~
art.cpp:81:34: error: 'ans' was not declared in this scope; did you mean 'abs'?
   81 |     for (int i = 1; i <= n; i++) ans[i - 1] = i;
      |                                  ^~~
      |                                  abs
art.cpp:82:21: error: 'ans' was not declared in this scope; did you mean 'abs'?
   82 |     int x = publish(ans);
      |                     ^~~
      |                     abs
art.cpp:85:20: error: expected primary-expression before 'int'
   85 |             vector<int> curr = ans;
      |                    ^~~
art.cpp:86:18: error: 'curr' was not declared in this scope
   86 |             swap(curr[i], curr[i - 1]);
      |                  ^~~~
art.cpp:86:13: error: 'swap' was not declared in this scope
   86 |             swap(curr[i], curr[i - 1]);
      |             ^~~~
art.cpp:86:13: note: suggested alternatives:
In file included from /usr/include/c++/11/set:62,
                 from art.cpp:3:
/usr/include/c++/11/bits/stl_multiset.h:1045:5: note:   'std::swap'
 1045 |     swap(multiset<_Key, _Compare, _Alloc>& __x,
      |     ^~~~
In file included from /usr/include/c++/11/bits/exception_ptr.h:43,
                 from /usr/include/c++/11/exception:153,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from art.cpp:1:
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
  196 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
In file included from /usr/include/c++/11/exception:153,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from art.cpp:1:
/usr/include/c++/11/bits/exception_ptr.h:223:5: note:   'std::__exception_ptr::swap'
  223 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/11/compare:39,
                 from /usr/include/c++/11/bits/stl_pair.h:65,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from art.cpp:1:
/usr/include/c++/11/concepts:227:43: note:   'std::ranges::__cust::swap'
  227 |       inline constexpr __cust_swap::_Swap swap{};
      |                                           ^~~~
/usr/include/c++/11/concepts:167:35: note:   'std::ranges::__cust_swap::swap'
  167 |       template<typename _Tp> void swap(_Tp&, _Tp&) = delete;
      |                                   ^~~~