Submission #762561

# Submission time Handle Problem Language Result Execution time Memory
762561 2023-06-21T13:47:32 Z KN200711 Baloni (COCI15_baloni) C++14
0 / 100
471 ms 131072 KB
# include <bits/stdc++.h>
using namespace std;

int arr[1000001];
bool vis[1000001];

set<int> pos[1000001];

int main() {
	int N;
	scanf("%d", &N);
	
	for(int i=1;i<=N;i++) {
		scanf("%d", &arr[i]);
		pos[arr[i]].insert(i);
		vis[i] = 0;
	}
	int ans = 0;
	for(int i=1;i<=N;i++) {
		if(vis[i]) continue;
		int K = i + 1, H = arr[i] - 1;
		vis[i] = 1;
		ans++;
		while(H) {
		//	cout<<H<<endl;
			auto p = pos[H].lower_bound(K);
			if(p == pos[H].end()) break;
		//	cout<<"vis"<<endl;
			vis[*p] = 1;
			K =  *p + 1;
			H--;
			pos[H].erase(p);
		}
	}
	printf("%d\n", ans);
}

Compilation message

baloni.cpp: In function 'int main()':
baloni.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
baloni.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d", &arr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 95656 KB Execution killed with signal 11
2 Runtime error 60 ms 95848 KB Execution killed with signal 11
3 Runtime error 66 ms 96048 KB Execution killed with signal 11
4 Runtime error 58 ms 96208 KB Execution killed with signal 11
5 Runtime error 418 ms 131072 KB Execution killed with signal 11
6 Runtime error 471 ms 131072 KB Execution killed with signal 11
7 Runtime error 388 ms 131072 KB Execution killed with signal 11
8 Runtime error 377 ms 131072 KB Execution killed with signal 11
9 Runtime error 442 ms 131072 KB Execution killed with signal 11
10 Runtime error 420 ms 131072 KB Execution killed with signal 11