답안 #870066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870066 2023-11-06T20:37:13 Z Matjaz Teams (CEOI11_tea) C++14
0 / 100
381 ms 26936 KB
//
//  CEOI11_TEA.cpp
//  
//
//  Created by Matjaz Leonardis on 06/11/2023.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<pair<int,int> > a(N);
    for (int i=0;i<N;i++){
        cin >> a[i].first;
        a[i].second = i + 1;
        
    }
    sort(a.begin(), a.end());
    
    vector<int> max_teams(N);
    vector<int> label(N);
    if (a[0].first == 1) {
        max_teams[0] = 1;
        label[0] = 1;
    } else max_teams[0] = 0;
    
    for (int i=1;i<N;i++){
        if (i < N - 1) max_teams[i] = max_teams[i-1]; else {
            label[i] = 1;
            max_teams[i] = (a[N-1].first == N ? 1 : 1 + max_teams[i - a[N-1].first]);
            continue;
        }
        
        if (i + 1 - a[i].first == 0){
            if (1 >= max_teams[i]){
                max_teams[i] = 1;
                label[i] = 1;
            }
        }
        
        if (i + 1 - a[i].first > 0 && max_teams[i-a[i].first] + 1 >= max_teams[i]){
            max_teams[i] = max_teams[i-a[i].first] + 1;
            label[i] = 1;
        }
    }
    
    cout << max_teams[N-1] << endl;
//    for (int i=0;i<N;i++) cout << max_teams[i] << " ";
//    cout << endl;
//    for (int i=0;i<N;i++) cout << label[i] << " ";
//    cout << endl;
    for (int ptr=N-1;ptr>=0;ptr--){
        if (label[ptr] != 0){
            
            vector<int> s;
            s.push_back(a[ptr].second);
            for (int i=1;i<a[ptr].first;i++){
                s.push_back(a[ptr - i].second);
            }
            ptr -= a[ptr].first;
            while (ptr >= 0 && label[ptr] == 0){
                s.push_back(a[ptr].second);
                ptr--;
            }
            cout << s.size();
            for (int i=0;i<s.size();i++) cout << " " << s[i];
            cout << endl;
            ptr++;
        }
    }
    
    return 0;
}

Compilation message

tea.cpp: In function 'int main()':
tea.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for (int i=0;i<s.size();i++) cout << " " << s[i];
      |                          ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Incorrect 2 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 2372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 252 ms 17300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 355 ms 23700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 26936 KB Output isn't correct
2 Halted 0 ms 0 KB -