Submission #1292949

#TimeUsernameProblemLanguageResultExecution timeMemory
1292949binminh01Watermelon (INOI20_watermelon)C++20
0 / 100
27 ms584 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double
#define sz(a) (int)a.size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define eb emplace_back
#define open(s) freopen(s, "r", stdin)
#define write(s) freopen(s, "w", stdout)
using pii = pair<int, int>;
using pll = pair<ll, ll>;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vdo;
typedef vector<vdo> vvdo;
typedef vector<string> vs;
typedef vector<pii> vpair;
typedef vector<vpair> vvpair;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi, greater<int>> pqg;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vll, greater<ll>> pqgll;
#define For(i, a, b) for (auto i = (a); i < (b); ++i)
#define FOR(i, a, b) for (auto i = (a); i <= (b); ++i)
#define Fore(i, a, b) for (auto i = (a); i >= (b); --i)
#define trav(i, a) for (auto &i: a)

int a[10], p[10], b[10];
int main() {
    if (fopen("watermelon.inp", "r")) freopen("watermelon.inp", "r", stdin), freopen("watermelon.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n, k; cin >> n >> k;
    For(i,0,n) cin >> a[i], p[i] = i + 1;
    do {
        bool ok = 1;
        Fore(i,n-1,0){
            b[i] = -1;
            int k = 1;
            For(j,i+1,n){
                if (p[i] < p[j]) {b[i] = k; break;}
                if (b[j] == -1) break;
                k = max(k, b[j] + 1);
            }
            if (a[i] != b[i]) {ok = 0; break;}
        }
        if (ok && --k == 0) {
            For(i,0,n) cout << p[i] << ' ';
            return 0;
        }
    } while (next_permutation(p, p + n));
    cout << -1;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:38:46: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     if (fopen("watermelon.inp", "r")) freopen("watermelon.inp", "r", stdin), freopen("watermelon.out", "w", stdout);
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:38:85: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     if (fopen("watermelon.inp", "r")) freopen("watermelon.inp", "r", stdin), freopen("watermelon.out", "w", stdout);
      |                                                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...