Submission #666266

# Submission time Handle Problem Language Result Execution time Memory
666266 2022-11-28T02:31:02 Z vuavisao Pancake (NOI12_pancake) C++14
0 / 25
1 ms 468 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;

const int N = 8 + 10;

bool cakeee(int* val);
bool special_case_zero();
bool special_case_one();
bool special_case_two();
void solve();

int n;
int a[N];

void solve() {
    cin >> n;
    for(int i = 1; i <= n; ++ i) cin >> a[i];
    a[0] = 1000000000;
    if(special_case_zero()) {
        cout << 0;
        return;
    }
    if(special_case_one()) {
        cout << 1;
        return;
    }
    if(special_case_two()) {
        cout << 2;
        return;
    }
    assert(false);
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("Cake.inp", "r")) {
        freopen("Cake.inp", "r", stdin);
        freopen("Cake.out", "w", stdout);
    }
    int t; cin >> t;
    while(t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

bool special_case_zero() {
    return cakeee(a);
}

bool special_case_one() {
    int tmp[N];
    for(int i = 1; i <= n; ++ i) {
        for(int j = 0; j <= n; ++ j) tmp[j] = a[j];
        reverse(tmp + i + 1, tmp + n + 1);
        if(cakeee(tmp)) return true;
    }
    return false;
}

bool special_case_two() {
    int tmp[N];
    for(int i = 1; i <= n; ++ i) {
        for(int j = 1; j <= n; ++ j) {
            for(int k = 0; k <= n; ++ k) tmp[k] = a[k];
            reverse(tmp + i + 1, tmp + n + 1);
            reverse(tmp + j + 1, tmp + n + 1);
            if(cakeee(tmp)) return true;
        }
    }
    return false;
}

bool cakeee(int* val) {
    for(int i = 1; i <= n; ++ i)
        if(val[i] > val[i - 1]) return false;
    return true;
}

/// Code by vuavisao

Compilation message

pancake.cpp: In function 'int32_t main()':
pancake.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen("Cake.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pancake.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("Cake.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -