Submission #487759

# Submission time Handle Problem Language Result Execution time Memory
487759 2021-11-16T14:32:52 Z errorgorn Volontiranje (COCI21_volontiranje) C++17
110 / 110
258 ms 135340 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

mt19937 rng(123123);

int n;
int arr[1000005];
int level[1000005];

vector<int> pos[1000005];

vector<int> v;

vector<vector<int> > ans;
vector<int> stk;

int lis;

bool dfs(int i){
	stk.pub(i);
	
	if (level[i]==lis){
		ans.pub(stk);
		return true;
	}
	
	while (!pos[level[i]+1].empty() && pos[level[i]+1].back()<i) pos[level[i]+1].pob();
	
	while (!pos[level[i]+1].empty() && arr[i]<arr[pos[level[i]+1].back()]){
		bool temp=dfs(pos[level[i]+1].back());
		pos[level[i]+1].pob();
		
		if (temp){
			return true;
		}
	}
	
	stk.pob();
	
	return false;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n;
	rep(x,0,n) cin>>arr[x];
	
	rep(x,0,n){
		if (v.empty() || v.back()<arr[x]){
			level[x]=sz(v);
			v.pub(arr[x]);
		}
		else{
			int idx=lb(all(v),arr[x])-v.begin();
			level[x]=idx;
			v[idx]=arr[x];
		}
	}
	
	lis=sz(v)-1;
	
	rep(x,n,0){
		pos[level[x]].pub(x);
	}
	
	//rep(x,0,n) cout<<level[x]<<" "; cout<<endl;
	
	while (!pos[0].empty()){
		stk.clear();
		dfs(pos[0].back());
		pos[0].pob();
	}
	
	cout<<sz(ans)<<" "<<lis+1<<endl;
	for (auto &it:ans){
		for (auto &it2:it) cout<<it2+1<<" "; cout<<endl;
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:96:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   96 |   for (auto &it2:it) cout<<it2+1<<" "; cout<<endl;
      |   ^~~
Main.cpp:96:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   96 |   for (auto &it2:it) cout<<it2+1<<" "; cout<<endl;
      |                                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23760 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23732 KB Output is correct
7 Correct 12 ms 23812 KB Output is correct
8 Correct 12 ms 23760 KB Output is correct
9 Correct 12 ms 23724 KB Output is correct
10 Correct 11 ms 23728 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 11 ms 23760 KB Output is correct
13 Correct 11 ms 23760 KB Output is correct
14 Correct 11 ms 23760 KB Output is correct
15 Correct 11 ms 23828 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23816 KB Output is correct
18 Correct 12 ms 23820 KB Output is correct
19 Correct 12 ms 23856 KB Output is correct
20 Correct 11 ms 23760 KB Output is correct
21 Correct 11 ms 23760 KB Output is correct
22 Correct 12 ms 23760 KB Output is correct
23 Correct 12 ms 23948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23760 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23732 KB Output is correct
7 Correct 12 ms 23812 KB Output is correct
8 Correct 12 ms 23760 KB Output is correct
9 Correct 12 ms 23724 KB Output is correct
10 Correct 11 ms 23728 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 11 ms 23760 KB Output is correct
13 Correct 11 ms 23760 KB Output is correct
14 Correct 11 ms 23760 KB Output is correct
15 Correct 11 ms 23828 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23816 KB Output is correct
18 Correct 12 ms 23820 KB Output is correct
19 Correct 12 ms 23856 KB Output is correct
20 Correct 11 ms 23760 KB Output is correct
21 Correct 11 ms 23760 KB Output is correct
22 Correct 12 ms 23760 KB Output is correct
23 Correct 12 ms 23948 KB Output is correct
24 Correct 12 ms 23760 KB Output is correct
25 Correct 12 ms 23760 KB Output is correct
26 Correct 11 ms 23812 KB Output is correct
27 Correct 11 ms 23816 KB Output is correct
28 Correct 12 ms 23760 KB Output is correct
29 Correct 12 ms 23812 KB Output is correct
30 Correct 12 ms 23888 KB Output is correct
31 Correct 12 ms 23760 KB Output is correct
32 Correct 12 ms 23792 KB Output is correct
33 Correct 12 ms 23760 KB Output is correct
34 Correct 12 ms 23760 KB Output is correct
35 Correct 12 ms 23816 KB Output is correct
36 Correct 11 ms 23760 KB Output is correct
37 Correct 12 ms 23740 KB Output is correct
38 Correct 12 ms 23732 KB Output is correct
39 Correct 12 ms 23760 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 11 ms 23712 KB Output is correct
42 Correct 11 ms 23760 KB Output is correct
43 Correct 12 ms 23760 KB Output is correct
44 Correct 11 ms 23728 KB Output is correct
45 Correct 12 ms 23816 KB Output is correct
46 Correct 11 ms 23740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23760 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23732 KB Output is correct
7 Correct 12 ms 23812 KB Output is correct
8 Correct 12 ms 23760 KB Output is correct
9 Correct 12 ms 23724 KB Output is correct
10 Correct 11 ms 23728 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 11 ms 23760 KB Output is correct
13 Correct 11 ms 23760 KB Output is correct
14 Correct 11 ms 23760 KB Output is correct
15 Correct 11 ms 23828 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23816 KB Output is correct
18 Correct 12 ms 23820 KB Output is correct
19 Correct 12 ms 23856 KB Output is correct
20 Correct 11 ms 23760 KB Output is correct
21 Correct 11 ms 23760 KB Output is correct
22 Correct 12 ms 23760 KB Output is correct
23 Correct 12 ms 23948 KB Output is correct
24 Correct 12 ms 23760 KB Output is correct
25 Correct 12 ms 23760 KB Output is correct
26 Correct 11 ms 23812 KB Output is correct
27 Correct 11 ms 23816 KB Output is correct
28 Correct 12 ms 23760 KB Output is correct
29 Correct 12 ms 23812 KB Output is correct
30 Correct 12 ms 23888 KB Output is correct
31 Correct 12 ms 23760 KB Output is correct
32 Correct 12 ms 23792 KB Output is correct
33 Correct 12 ms 23760 KB Output is correct
34 Correct 12 ms 23760 KB Output is correct
35 Correct 12 ms 23816 KB Output is correct
36 Correct 11 ms 23760 KB Output is correct
37 Correct 12 ms 23740 KB Output is correct
38 Correct 12 ms 23732 KB Output is correct
39 Correct 12 ms 23760 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 11 ms 23712 KB Output is correct
42 Correct 11 ms 23760 KB Output is correct
43 Correct 12 ms 23760 KB Output is correct
44 Correct 11 ms 23728 KB Output is correct
45 Correct 12 ms 23816 KB Output is correct
46 Correct 11 ms 23740 KB Output is correct
47 Correct 82 ms 32180 KB Output is correct
48 Correct 97 ms 32584 KB Output is correct
49 Correct 106 ms 35408 KB Output is correct
50 Correct 170 ms 44288 KB Output is correct
51 Correct 62 ms 28556 KB Output is correct
52 Correct 258 ms 135340 KB Output is correct
53 Correct 248 ms 105012 KB Output is correct
54 Correct 212 ms 53396 KB Output is correct
55 Correct 207 ms 53324 KB Output is correct
56 Correct 13 ms 24016 KB Output is correct
57 Correct 147 ms 40320 KB Output is correct
58 Correct 42 ms 27580 KB Output is correct
59 Correct 39 ms 27048 KB Output is correct
60 Correct 153 ms 40776 KB Output is correct
61 Correct 99 ms 34516 KB Output is correct
62 Correct 11 ms 23760 KB Output is correct
63 Correct 11 ms 23800 KB Output is correct
64 Correct 12 ms 23888 KB Output is correct
65 Correct 11 ms 23768 KB Output is correct
66 Correct 12 ms 23812 KB Output is correct
67 Correct 12 ms 23816 KB Output is correct
68 Correct 12 ms 23720 KB Output is correct
69 Correct 12 ms 23812 KB Output is correct