답안 #815876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815876 2023-08-09T01:52:58 Z Pikachu 사육제 (CEOI14_carnival) C++17
100 / 100
26 ms 356 KB
#include <bits/stdc++.h>

using namespace std;

template<typename T>
inline bool maxi(T &x, const T &val)
{
    if (x < val) return x = val, true;
    return false;
}

template<typename T>
inline bool mini(T &x, const T &val)
{
    if (x > val) return x = val, true;
    return false;
}

const int maxn = 155;
int n;
int ans[maxn];
bool last[maxn];
set<int> rem;

int getint()
{
    int tmp;
    cin >> tmp;
    return tmp;
}

int askrange(int l, int r)
{
    cout << r - l + 1 << ' ';
    for (int i = l; i <= r; i++) {
        cout << i << ' ';
    }
    cout << endl;
    return getint();
}

int askpair(int u, int v)
{
    cout << 2 << ' ' << u << ' ' << v << endl;
    return getint();
}

void erase(vector<int> &tmp)
{
    for (int x : tmp) {
        rem.erase(x);
    }
    tmp.clear();
}

void solve()
{
    cin >> n;
    int cur = askrange(1, n);
    last[n] = true;
    for (int i = 1; i < n; i++) {
        if (askrange(i + 1, n) != cur) {
            last[i] = true;
            cur--;
        }
        else rem.insert(i);
    }
    int cnt = 0;
    vector<int> tmp;
    for (int i = 1; i <= n; i++) {
        if (last[i]) {
            ans[i] = ++cnt;
            for (int x : rem) {
                if (x > i) break;
                if (askpair(x, i) == 1) {
                    ans[x] = cnt;
                    tmp.push_back(x);
                }
            }
            erase(tmp);
        }
    }
    cout << "0 ";
    for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
    cout << endl;
}

signed main()
{
#ifdef LOCAL
    clock_t st = clock();
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

#define Task ""
#ifdef LOCAL
    if (!fopen("D:\\.inp", "r")) {
        freopen("D:\\.inp", "w", stdout);
        freopen("D:\\.out", "w", stdout);
        cerr << "get input from file\n";
        return 0;
    }
    freopen("D:\\.inp", "r", stdin);
    freopen("D:\\.out", "w", stdout);
#else
    if (fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
#endif

    solve();

#ifdef LOCAL
    cerr << clock() - st << endl;
#endif
}   

Compilation message

carnival.cpp: In function 'int main()':
carnival.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(Task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
carnival.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 208 KB Output is correct
2 Correct 16 ms 256 KB Output is correct
3 Correct 10 ms 312 KB Output is correct
4 Correct 6 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 3 ms 316 KB Output is correct
7 Correct 13 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 13 ms 316 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 7 ms 208 KB Output is correct
5 Correct 13 ms 208 KB Output is correct
6 Correct 9 ms 320 KB Output is correct
7 Correct 12 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 5 ms 320 KB Output is correct
3 Correct 13 ms 208 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 21 ms 320 KB Output is correct
6 Correct 9 ms 356 KB Output is correct
7 Correct 22 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 320 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 12 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
5 Correct 14 ms 208 KB Output is correct
6 Correct 26 ms 236 KB Output is correct
7 Correct 16 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 15 ms 256 KB Output is correct
4 Correct 6 ms 316 KB Output is correct
5 Correct 20 ms 208 KB Output is correct
6 Correct 20 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct