답안 #145710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145710 2019-08-20T20:15:58 Z jacynkaa Teams (CEOI11_tea) C++14
100 / 100
615 ms 79688 KB
#include <bits/stdc++.h>
#include <math.h>
#include <chrono>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10) //cin.tie(0); cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define what(x) cerr << #x << " is " << x << endl;

const int MAXN = 1e6 + 1e2;
vector<pii> L;
int dp[MAXN];
bool brac[MAXN];
int n;

void solve()
{
    for (int i = 1; i <= n; i++)
    {
        if ((i - L[i].st >= 0 && dp[i - L[i].st] + 1 >= dp[i - 1]) || i == n)
        {
            brac[i] = true;
            dp[i] = dp[i - L[i].st] + 1;
        }
        else
            dp[i] = dp[i - 1];
    }
    vector<vector<int>> W;
    //cout << dp[n] << endl;

    int j = n;
    while (j > 0)
    {

        vector<int> X;
        int k = j;
        for (; (k > j - L[j].st || brac[k] == false) && k > 0; k--)
            X.pb(L[k].nd);
        j = k;
        W.pb(X);
    }
    reverse(all(W));

    int sum = 0;
    int k = 0;
    for (int i = W.size() - 1; i >= 0; i--)
    {
        sum += W[i].size();
        k = max(k, (int)ceil((long double)sum / (long double)(W.size() - i)));
    }
    cout << W.size() << endl;
    //cerr << k << endl;
    rep(i, W.size())
    {
        while (W[i].size() > k)
        {
            W[i + 1].pb(W[i].back());
            W[i].pop_back();
        }
        cout << W[i].size() << " ";
        for (auto a : W[i])
            cout << a << " ";
        cout << endl;
    }
}
main()
{
    _upgrade;
    cin >> n;
    L.resize(n + 1);
    L[0] = {0, 0};
    rep(i, n)
    {
        cin >> L[i].st;
        L[i].nd = i + 1;
    }
    sort(all(L));
    solve();
}

Compilation message

tea.cpp: In function 'void solve()':
tea.cpp:15:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i = 0; i < (n); ++i)
                                     ^
tea.cpp:63:5: note: in expansion of macro 'rep'
     rep(i, W.size())
     ^~~
tea.cpp:65:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (W[i].size() > k)
                ~~~~~~~~~~~~^~~
tea.cpp: At global scope:
tea.cpp:76:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 416 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 528 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2952 KB Output is correct
2 Correct 25 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3188 KB Output is correct
2 Correct 25 ms 2556 KB Output is correct
3 Correct 30 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 21472 KB Output is correct
2 Correct 235 ms 20892 KB Output is correct
3 Correct 249 ms 23124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 30256 KB Output is correct
2 Correct 615 ms 79688 KB Output is correct
3 Correct 314 ms 27320 KB Output is correct
4 Correct 308 ms 25872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 367 ms 32428 KB Output is correct
2 Correct 420 ms 30868 KB Output is correct
3 Correct 312 ms 27896 KB Output is correct
4 Correct 346 ms 29664 KB Output is correct