답안 #165824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165824 2019-11-29T08:55:17 Z Abdulaziz_Kazim Baloni (COCI15_baloni) C++17
0 / 100
51 ms 47480 KB
#include<bits/stdc++.h>
using namespace std;
int dizi[1000007];
vector<int> cnt[1000007];
list<int> r[1000007];
bool visit[1000007];
int main()
{
	freopen("a.gir","r",stdin);
	freopen("a.cik","w",stdout);	
	// cout << "yarrr";
	int n;
	cin >> n;
	// cout << "ar"; 
	// memset(cnt,-1,sizeof(cnt));
	// memset(r,-1,sizeof(r));
	for(int i=0;i<n;i++)
	{
		cin >> dizi[i];

	}
	// cout << "adasd";

	cnt[dizi[n-1]].push_back(n-1);
	for(int i=n-2;i>=0;i--)
	{
		// cout << i << " "; 
		if(cnt[dizi[i]-1].size()>0)
		{
			for(auto x:cnt[dizi[i]-1])
				r[i].push_front(x);
			// r[i].push_back(cnt[dizi[i]-1]);
		}
		cnt[dizi[i]].push_back(i);
	}
	// cout << endl;
	// for(int i=0;i<n;i++)
	// {
	// 	for(auto x:r[i])
	// 		cout << x << " ";
	// 	cout << endl;
	// 	// cout << r[i] << " ";
	// }
	// free(cnt);
	long long int sayac=0;
	for(int i=0;i<n;i++)
	{
		if(visit[i]==1)
			continue;
		sayac++;
		while(!r[i].empty()&&visit[r[i].front()]==1)
			r[i].pop_front();
		int ptr=i;
		while(!r[ptr].empty() && visit[r[ptr].front()]!=1)
		{
			visit[ptr]=1;
			ptr=r[ptr].front();
			// cout << ptr << " ";
		}
		visit[ptr]=1;
		// cout << endl;
	}
	// cout << visit[7] << " ";
	cout << sayac;
}

Compilation message

baloni.cpp: In function 'int main()':
baloni.cpp:9:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("a.gir","r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~
baloni.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("a.cik","w",stdout); 
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 47352 KB Output isn't correct
2 Incorrect 48 ms 47352 KB Output isn't correct
3 Incorrect 51 ms 47352 KB Output isn't correct
4 Incorrect 49 ms 47444 KB Output isn't correct
5 Incorrect 49 ms 47224 KB Output isn't correct
6 Incorrect 49 ms 47352 KB Output isn't correct
7 Incorrect 48 ms 47224 KB Output isn't correct
8 Incorrect 49 ms 47480 KB Output isn't correct
9 Incorrect 49 ms 47224 KB Output isn't correct
10 Incorrect 50 ms 47236 KB Output isn't correct