Submission #745246

# Submission time Handle Problem Language Result Execution time Memory
745246 2023-05-19T15:43:39 Z Ahmed57 Volontiranje (COCI21_volontiranje) C++17
0 / 110
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> v;
    for(int i = 0;i<n;i++){
        int x;cin>>x;
        v.push_back({x,i});
    }
    int be = -1, cnt = 0;
    vector<vector<pair<int,int>>> ans;
    while(1){
        int dp[v.size()] = {0};
        int pr[v.size()] = {0};
        int all= 0 ,index = 0;
        for(int i=0 ;i<v.size();i++){
            int ma = 0, ind =i;
            for(int j = i-1;j>=0;j--){
                if(v[i].first>v[j].first){
                    if(ma<dp[j]){
                        ma=dp[j];
                        ind = j;
                    }
                }
            }
            dp[i] = ma+1;
            pr[i] = ind;
            if(all<dp[i]){
                all= dp[i];
                index = i;
            }
        }
        if(all<be){
            break;
        }
        cnt++;
        be = all;
        ans.push_back({});
        while(pr[index]!=index){
            ans.back().push_back({index,v[index].second});
            index= pr[index];
        }ans.back().push_back({index,v[index].second});
        vector<pair<int,int>> z;int cnt = 0;
        reverse(ans.back().begin(),ans.back().end());
        for(int i = 0;i<ans.back().size();i++){
            while(cnt<ans.back()[i].first){
                z.push_back(v[cnt++]);
            }
            cnt++;
        }
        while(cnt<v.size()){
            z.push_back(v[cnt++]);
        }
        v = z;
    }
    cout<<cnt<<" "<<be<<endl;
    for(auto i:ans){
        for(auto j:i){
            cout<<j.second+1<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for(int i=0 ;i<v.size();i++){
      |                      ~^~~~~~~~~
Main.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i = 0;i<ans.back().size();i++){
      |                       ~^~~~~~~~~~~~~~~~~~
Main.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while(cnt<v.size()){
      |               ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -