답안 #1019435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019435 2024-07-10T20:32:35 Z TAhmed33 Volontiranje (COCI21_volontiranje) C++
0 / 110
13 ms 23900 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 25;
int p[MAXN], n;
int cur[MAXN];
vector <int> dd[MAXN];
void solve () {
    cin >> n;
    cur[0] = -MAXN;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        cur[i] = MAXN;
    }
    int v = 0;
    for (int i = 1; i <= n; i++) {
        int g = upper_bound(cur, cur + n + 1, p[i]) - cur;
        dd[g].push_back(i);
        cur[g] = p[i];
        v = max(v, g);
    }
    for (int i = 1; i <= v; i++) {
        reverse(dd[i].begin(), dd[i].end());
    }
    vector <vector <int>> ans;
    while (true) {
        if (dd[1].empty()) {
            break;
        }
        bool f = 0;
        for (int i = 2; i <= v; i++) {
            while (!dd[i].empty() && dd[i].back() < dd[i - 1].back()) {
                dd[i].pop_back();
            }
            if (dd[i].empty()) {
                f = 1;
                break;
            }
            if (p[dd[i].back()] < p[dd[i - 1].back()]) {
                dd[i - 1].pop_back();
                i--;
            }
        }
        if (f) {
            break;
        }
        vector <int> gg;
        for (int i = 1; i <= v; i++) {
            if (dd[i].empty()) {
                f = 1;
                break;
            }
            gg.push_back(dd[i].back());
            dd[i].pop_back();
        }
        if (f) {
            break;
        }
        ans.push_back(gg);
    }
    cout << int(ans.size()) << ' ' << v << '\n';
    for (auto i : ans) {
        for (auto j : i) {
            cout << j << " ";
        }
        cout << '\n';
    }
}       
signed main () {
    #ifndef ONLINE_JUDGE 
        freopen("input_file", "r", stdin);
        freopen("output_file", "w", stdout);
    #endif
    ios::sync_with_stdio(0); cin.tie(0);
    int tc = 1; //cin >> tc;
    while (tc--) solve();
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("input_file", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen("output_file", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23900 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23900 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23900 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -