Submission #593032

# Submission time Handle Problem Language Result Execution time Memory
593032 2022-07-10T08:53:17 Z pooyashams Watermelon (INOI20_watermelon) C++14
31 / 100
26 ms 4976 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define endl '\n'
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5+10;

int brr[maxn];
int ans[maxn];

int bef[maxn];
int aft[maxn];

inline void die()
{
	cout << -1 << endl;
	exit(0);
}

inline void join(int x)
{
	int b = bef[x];
	int a = aft[x];
	bef[a] = b;
	aft[b] = a;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k; // k == 1
	set<int> rems;
	aft[0] = 1;
	int c = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> brr[i];
		c += (brr[i] != -1);
		if(brr[i] == 1)
			rems.insert(i);
		bef[i] = i-1;
		aft[i] = i+1;
	}
	int d = n;
	for(int i = 1; i <= n; i++)
	{
		if(brr[i] != -1) continue;
		ans[i] = d--;
		join(i);
	}
	bef[n+1] = n;
	for(int i = 1; i <= c; i++)
	{
		if(rems.empty())
			die();
		int x = *rems.begin();
		rems.erase(rems.begin());
		ans[x] = i;
		if(brr[bef[x]] == brr[x]+1)
			rems.insert(bef[x]);
		join(x);
	}
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";
	cout << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2576 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 16 ms 2676 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 14 ms 2568 KB Output is correct
6 Correct 12 ms 2624 KB Output is correct
7 Correct 12 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 13 ms 2648 KB Output is correct
10 Correct 13 ms 2636 KB Output is correct
11 Correct 26 ms 4940 KB Output is correct
12 Correct 26 ms 4948 KB Output is correct
13 Correct 26 ms 4948 KB Output is correct
14 Correct 26 ms 4976 KB Output is correct
15 Correct 8 ms 2008 KB Output is correct
16 Correct 8 ms 2008 KB Output is correct
17 Correct 8 ms 2004 KB Output is correct
18 Correct 8 ms 1948 KB Output is correct
19 Correct 8 ms 2004 KB Output is correct
20 Correct 8 ms 2004 KB Output is correct
21 Correct 8 ms 2004 KB Output is correct
22 Correct 8 ms 2004 KB Output is correct
23 Correct 7 ms 2008 KB Output is correct
24 Correct 18 ms 2948 KB Output is correct
25 Correct 17 ms 2872 KB Output is correct
26 Correct 18 ms 2904 KB Output is correct
27 Correct 18 ms 2908 KB Output is correct
28 Correct 18 ms 2892 KB Output is correct
29 Correct 18 ms 2900 KB Output is correct
30 Correct 6 ms 984 KB Output is correct
31 Correct 9 ms 1500 KB Output is correct
32 Correct 16 ms 2516 KB Output is correct
33 Correct 19 ms 2824 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 4 ms 724 KB Output is correct
36 Correct 9 ms 1528 KB Output is correct
37 Correct 18 ms 2772 KB Output is correct
38 Correct 19 ms 3068 KB Output is correct
39 Correct 18 ms 2764 KB Output is correct
40 Correct 24 ms 4936 KB Output is correct
41 Correct 17 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2576 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 16 ms 2676 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 14 ms 2568 KB Output is correct
6 Correct 12 ms 2624 KB Output is correct
7 Correct 12 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 13 ms 2648 KB Output is correct
10 Correct 13 ms 2636 KB Output is correct
11 Correct 26 ms 4940 KB Output is correct
12 Correct 26 ms 4948 KB Output is correct
13 Correct 26 ms 4948 KB Output is correct
14 Correct 26 ms 4976 KB Output is correct
15 Correct 8 ms 2008 KB Output is correct
16 Correct 8 ms 2008 KB Output is correct
17 Correct 8 ms 2004 KB Output is correct
18 Correct 8 ms 1948 KB Output is correct
19 Correct 8 ms 2004 KB Output is correct
20 Correct 8 ms 2004 KB Output is correct
21 Correct 8 ms 2004 KB Output is correct
22 Correct 8 ms 2004 KB Output is correct
23 Correct 7 ms 2008 KB Output is correct
24 Correct 18 ms 2948 KB Output is correct
25 Correct 17 ms 2872 KB Output is correct
26 Correct 18 ms 2904 KB Output is correct
27 Correct 18 ms 2908 KB Output is correct
28 Correct 18 ms 2892 KB Output is correct
29 Correct 18 ms 2900 KB Output is correct
30 Correct 6 ms 984 KB Output is correct
31 Correct 9 ms 1500 KB Output is correct
32 Correct 16 ms 2516 KB Output is correct
33 Correct 19 ms 2824 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 4 ms 724 KB Output is correct
36 Correct 9 ms 1528 KB Output is correct
37 Correct 18 ms 2772 KB Output is correct
38 Correct 19 ms 3068 KB Output is correct
39 Correct 18 ms 2764 KB Output is correct
40 Correct 24 ms 4936 KB Output is correct
41 Correct 17 ms 2972 KB Output is correct
42 Incorrect 13 ms 2644 KB Output isn't correct
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -