답안 #91171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91171 2018-12-26T12:45:24 Z davitmarg Money (IZhO17_money) C++17
0 / 100
2 ms 372 KB
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>  
#include <fstream>  
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
int n,ans,a[1000006],l;
set<int> s;
stack<int> st;
set<int>::iterator it;
int main()
{
	cin >> n;
	ans = 1;
	for (int i = 1; i <= n; i++)
		scanf("%d", a+i);
	s.insert(0);
	it = s.end();
	for (int i = 1; i <= n; i++)
	{
		if ((a[i] < a[i - 1]) || it != s.end() && (*it) < a[i] )
		{
			l = a[i];
			it = s.upper_bound(l);
			ans++;
			while (!st.empty())
			{
				s.insert(st.top());
				st.pop();
			}
		}
		st.push(a[i]);
	}

	cout << ans << endl;
	return 0;
}

/*

6
1 3 5 2 4 6

*/

Compilation message

money.cpp: In function 'int main()':
money.cpp:40:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if ((a[i] < a[i - 1]) || it != s.end() && (*it) < a[i] )
                            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
money.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 372 KB Output isn't correct
3 Halted 0 ms 0 KB -