제출 #1321043

#제출 시각아이디문제언어결과실행 시간메모리
1321043duckindogSecret Permutation (RMI19_permutation)C++20
컴파일 에러
0 ms0 KiB
#include <algorithm>
#include <bits/stdc++.h>
#include <random>

#ifndef LOCAL
#include "permutationc.h"
#endif

using namespace std;

#ifdef LOCAL
vector<int> GLOBAL;
void answer(vector<int> P) { 
    assert(P == GLOBAL);
}
int query(vector<int> V) { 
    int ret = 0;
    for (int i = 0; i < (int)V.size() - 1; ++i) { 
        ret += abs(GLOBAL[V[i]] - GLOBAL[V[i + 1]]);
    }
    return ret;
}
#endif

mt19937 rng(49853495);

void solve(int N) { 
    vector<vector<int>> V(N, vector<int>(N));
    vector<int> value(N);
    for (int i = 0; i < N; ++i) { 
        iota(V[i].begin(), V[i].end(), 1);
        shuffle(V[i].begin(), V[i].end(), rng);
        value[i] = query(V[i]);
    }

    vector<int> v(N); iota(v.begin(), v.end(), 1);
    do { 
        bool isValid = true;
        for (int i = 0; i < N; ++i) { 
            int ret = 0;
            for (int j = 0; j < N - 1; ++j) ret += abs(v[V[i][j] - 1] - v[V[i][j]]);
            if (ret != value[i]) { 
                isValid = false; break;
            }
        }
        if (isValid) { 
            answer(v); return;
        }
    } while (next_permutation(v.begin(), v.end()));
}

#ifdef LOCAL
int32_t main() { 
    cin.tie(0)->sync_with_stdio(0);

    int N; cin >> N;
    GLOBAL.resize(N);
    for (auto& x : GLOBAL) cin >> x;

    solve(N);
}
#endif

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

permutation.cpp: In function 'void solve(int)':
permutation.cpp:33:25: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'int*'
   33 |         value[i] = query(V[i]);
      |                    ~~~~~^~~~~~
      |                         |
      |                         __gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type {aka std::vector<int>}
In file included from permutation.cpp:6:
permutationc.h:2:15: note:   initializing argument 1 of 'int query(int*)'
    2 | int query(int v[]);
      |           ~~~~^~~
permutation.cpp:47:20: error: cannot convert 'std::vector<int>' to 'int*'
   47 |             answer(v); return;
      |                    ^
      |                    |
      |                    std::vector<int>
permutationc.h:3:17: note:   initializing argument 1 of 'void answer(int*)'
    3 | void answer(int v[]);
      |             ~~~~^~~
stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~