답안 #240783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240783 2020-06-21T07:32:11 Z kartel Zagonetka (COI18_zagonetka) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +200500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define pii pair <int, int>
#define err ld(1e-9)
#define last(x) x.back()
#define all(x) (x.begin(), x.end())
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

vector <int> q, ans[2];
int i, p[N], n;
bool mrk[N];

bool check(vector <int> &q)
{
    int ch;

    cout << "query";
    for (auto x : q) cout << " " << x;
    cout << endl;

    cin >> ch;
    return bool(ch);
}

void lower(vector <int> &q)
{
    int i = 0;
    while (i < n && q[i] == ans[0][i]) i++;

    if (i == n || q[i] < ans[0][i]) ans[0] = q;
}

void upper(vector <int> &q)
{
    int i = 0;
    while (i < n && q[i] == ans[1][i]) i++;

    if (i == n || q[i] > ans[1][i]) ans[1] = q;
}

void rec(int k)
{
    if (k == n)
    {
        if (check(q))
        {
            lower(q);
            upper(q);
        }
        return;
    }

    for (int i = 1; i <= n; i++)
        if (!mrk[i])
    {
        mrk[i] = 1;
        q.pb(i);

        rec(k + 1);

        q.pop_back();
        mrk[i] = 0;
    }
}

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> n;
    for (i = 0; i < n; i++) cin >> p[i];

    ans[0].resize(n);
    ans[1].resize(n);
//    q.resize(n);

    i = 0;
    for (i = 0; i < n; i++) ans[0][i] = n - i, ans[1][i] = i + 1;

    if (n <= 6)
        rec(0);
    else
    {
        pair <int, int> cond;
        bool fnd = 0;
        for (i = 1; i <= n && !fnd; i++)
           for (j = 1; j <= n && !fnd; j++)
           if (i != j)
        {
            swap(p[i], p[j]);

            if (!check(p))
                {
                    cond = {i, j};
                    fnd = 1;
                    break;
                }
        }

        if (cond.F > cond.S) swap(ans[0][cond.F], ans[0][cond.S]);
        if (cond.F < cond.S) swap(ans[1][cond.F], ans[1][cond.S]);
    }

    cout << "end" << endl;
    for (auto x : ans[0]) cout << x << " ";
    cout << endl;
    for (auto x : ans[1]) cout << x << " ";
    cout << endl;
}

//2 1
//3 4

Compilation message

zagonetka.cpp: In function 'int main()':
zagonetka.cpp:114:17: error: 'j' was not declared in this scope
            for (j = 1; j <= n && !fnd; j++)
                 ^
zagonetka.cpp:119:25: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'int [200500]'
             if (!check(p))
                         ^
zagonetka.cpp:32:6: note: in passing argument 1 of 'bool check(std::vector<int>&)'
 bool check(vector <int> &q)
      ^~~~~
zagonetka.cpp:121:33: error: no match for 'operator=' (operand types are 'std::pair<int, int>' and '<brace-enclosed initializer list>')
                     cond = {i, j};
                                 ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from zagonetka.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:367:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type = const std::pair<int, int>&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:367:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, const std::pair<int, int>&, const std::__nonesuch_no_braces&>::type {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_pair.h:384:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type = std::pair<int, int>&&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:384:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::conditional<true, std::pair<int, int>&&, std::__nonesuch_no_braces&&>::type {aka std::pair<int, int>&&}'
/usr/include/c++/7/bits/stl_pair.h:400:2: note: candidate: template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]
  operator=(const pair<_U1, _U2>& __p)
  ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:400:2: note:   template argument deduction/substitution failed:
zagonetka.cpp:121:33: note:   couldn't deduce template parameter '_U1'
                     cond = {i, j};
                                 ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from zagonetka.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:411:2: note: candidate: template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]
  operator=(pair<_U1, _U2>&& __p)
  ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:411:2: note:   template argument deduction/substitution failed:
zagonetka.cpp:121:33: note:   couldn't deduce template parameter '_U1'
                     cond = {i, j};
                                 ^