답안 #759537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759537 2023-06-16T12:02:16 Z otarius Election (BOI18_election) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long

// #define int long long
// #define int unsigned long long

const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;

bool check(vector<int> v, int n) {
    set<int> st;
    for (int u : v)
        st.insert(u);
    if (st.size() != n)
        return false;
    int cur = 1;
    for (int u : st) {
        if (cur == u)
            cur++;
        else return false;
    } return true;
}
void solve(int n) {
    int b[n + 1], c[n + 1];
    for (int i = 1; i <= n - 1; i++)
        b[i] = query(i, i + 1);
    for (int i = 1; i <= n - 2; i++)
        c[i] = query(i, i + 2);
    bool flg[n + 1];
    /*
        flg[i] = 1, if a[i] > a[i + 1]
        flg[i] = 0, if a[i] < a[i + 1]
    */ flg[1] = 1;
    for (int i = 2; i <= n - 1; i++) {
        if (b[i - 1] + b[i] == c[i - 1])
            flg[i] = flg[i - 1];
        else flg[i] = !flg[i - 1];
    } int cur = 1, mn = 1; vector<int> a;
    for (int i = 2; i <= n; i++) {
        if (flg[i - 1] == 1) {
            cur -= b[i - 1];
            a.pb(cur); mn = min(mn, cur);
        } else {
            cur += b[i - 1];
            a.pb(cur); mn = min(mn, cur);
        }
    } for (int &v : a)
        v += -mn + 1;
    if (check(v, n)) {
        for (int i = 0; i < a.size(); i++)
            answer(i + 1, a[i]);
        return;
    } cur = 1; mn = 1; a.clear();
    for (int i = 2; i <= n; i++) {
        if (flg[i - 1] == 1) {
            cur += b[i - 1]
            a.pb(cur); mn = min(mn, cur);
        } else {
            cur += b[i - 1];
            a.pb(cur); mn = min(mn, cur);
        }
    } for (int &v : a)
        v += -mn + 1;
    for (int i = 0; i < a.size(); i++)
        answer(i + 1, a[i]);
}

Compilation message

election.cpp: In function 'bool check(std::vector<int>, int)':
election.cpp:30:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |     if (st.size() != n)
      |         ~~~~~~~~~~^~~~
election.cpp: In function 'void solve(int)':
election.cpp:42:16: error: 'query' was not declared in this scope
   42 |         b[i] = query(i, i + 1);
      |                ^~~~~
election.cpp:44:16: error: 'query' was not declared in this scope
   44 |         c[i] = query(i, i + 2);
      |                ^~~~~
election.cpp:65:15: error: 'v' was not declared in this scope
   65 |     if (check(v, n)) {
      |               ^
election.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i = 0; i < a.size(); i++)
      |                         ~~^~~~~~~~~~
election.cpp:67:13: error: 'answer' was not declared in this scope
   67 |             answer(i + 1, a[i]);
      |             ^~~~~~
election.cpp:72:28: error: expected ';' before 'a'
   72 |             cur += b[i - 1]
      |                            ^
      |                            ;
   73 |             a.pb(cur); mn = min(mn, cur);
      |             ~               
election.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
election.cpp:81:9: error: 'answer' was not declared in this scope
   81 |         answer(i + 1, a[i]);
      |         ^~~~~~