답안 #1111365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111365 2024-11-12T07:44:12 Z DuongKiet Teams (CEOI11_tea) C++17
80 / 100
246 ms 73948 KB
#include <bits/stdc++.h>
#define N 1000005
#define inf 1e18
#define ll long long
#define ii pair <int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define SZ(x) (int) x.size()

const long long Mod = 1e9 + 7;

using namespace std;

int n;
struct cauthu{
    int c, id;
}a[N];
struct slteam{
    int c, id;
};
struct cmp{
    bool operator()(slteam &a, slteam &b){
        return a.c > b.c;
    }
};
void init(){

    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i].c;
        a[i].id = i;
    }
    sort(a + 1, a + 1 + n, [&](cauthu a, cauthu b){
            if (a.c == b.c) return a.id > b.id;
            return a.c > b.c;
        });
    vector <vector<int> > team;
    vector <int> maketeam;
    int cur = -1;
    for (int i = 1; i <= n; i++){
        if (cur == -1){
            cur = a[i].c - 1;
            maketeam.pb(a[i].id);
            continue;
        }
        if (cur > 0){
            cur--;
            maketeam.pb(a[i].id);
        }else{
            cur = a[i].c - 1;
            team.pb(maketeam);
            maketeam.clear();
            maketeam.pb(a[i].id);
        }
    }
    if (cur > 0){

        priority_queue<slteam, vector <slteam>, cmp> q;
        for (int i = 0; i < SZ(team); i++)
            q.push({SZ(team[i]), i});

        sort(all(maketeam), [&](int u, int v){return a[u].c < a[v].c;});

        while (a[maketeam.back()].c > SZ(maketeam) && !maketeam.empty()){
            slteam k = q.top();
            q.pop();
            team[k.id].pb(maketeam.back());
            q.push({SZ(team[k.id]), k.id});
            maketeam.pop_back();
            if (maketeam.empty()) break;
        }
        if (!maketeam.empty()) team.pb(maketeam);
//        cout << "YES";
//        cout << maketeam.back();
    }
    else if (!maketeam.empty()) team.pb(maketeam);
    cout << team.size() << '\n';
    for (vector <int> cur: team){
        cout << cur.size() << ' ';
        for (int x: cur)
            cout << x << " ";
        cout << '\n';
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #define task "task"
    if (fopen(task".inp", "r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    init();
    return 0;
}

Compilation message

tea.cpp: In function 'int main()':
tea.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tea.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3664 KB Output is correct
2 Correct 15 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3920 KB Output is correct
2 Correct 15 ms 3664 KB Output is correct
3 Correct 18 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 15436 KB Output is correct
2 Correct 129 ms 15916 KB Output is correct
3 Correct 146 ms 16236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 19800 KB Output is correct
2 Correct 246 ms 73948 KB Output is correct
3 Correct 180 ms 19844 KB Output is correct
4 Correct 183 ms 17168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 23316 KB Output is correct
2 Correct 126 ms 27064 KB Output is correct
3 Correct 170 ms 19068 KB Output is correct
4 Correct 198 ms 19640 KB Output is correct