Submission #76849

# Submission time Handle Problem Language Result Execution time Memory
76849 2018-09-18T15:59:48 Z zetapi Gift (IZhO18_nicegift) C++14
18 / 100
2000 ms 104688 KB
#include "bits/stdc++.h"
using namespace std;

#define pb  push_back
#define mp  make_pair
#define	int long long
#define itr iterator

typedef pair<int,int> pii;

const int MAX=5e6;

set<pii> st;

set<pii>::itr it_1,it_2;

vector<pii> res;

int N,K,sum,arr[MAX];

void print_1()
{
	assert(!(st.size()%2));
	while(!st.empty())
	{
		it_1=st.begin();
		it_2=it_1;
		it_2++;
		res.pb(mp(it_1->second,it_2->second));
		st.erase(it_1);
		st.erase(it_2);
	}
	cout<<res.size()<<"\n";
	for(int A=0;A<res.size();A++)
		cout<<1<<" "<<res[A].first<<" "<<res[A].second<<"\n";
	return ;
}

signed main()
{
	ios_base::sync_with_stdio(false);

	cin>>N>>K;
	for(int A=1;A<=N;A++)
	{
		cin>>arr[A];
		sum+=arr[A];
		if(arr[A])
			st.insert(mp(-arr[A],A));
	}
	if(sum%2)
		return cout<<-1,0;
	while(true)
	{
		if(st.size()<=1)
			return cout<<-1,0;
		it_1=st.begin();
		it_2=it_1;
		it_2++;
		pii p=*it_1;
		pii q=*it_2;
		if(p.first==-1)
		{
			print_1();
			break;
		}
		p.first++;
		q.first++;
		st.erase(it_1);
		st.erase(it_2);
		if(p.first!=0)
			st.insert(p);
		if(q.first!=0)
			st.insert(q);
		res.pb(mp(p.second,q.second));
		/*for(auto A:st)
			cout<<-A.first<<" ";
		cout<<"\n";*/
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'void print_1()':
nicegift.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=0;A<res.size();A++)
              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 416 KB n=3
4 Correct 3 ms 420 KB n=4
5 Correct 2 ms 540 KB n=4
6 Correct 2 ms 632 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 416 KB n=3
4 Correct 3 ms 420 KB n=4
5 Correct 2 ms 540 KB n=4
6 Correct 2 ms 632 KB n=2
7 Correct 2 ms 632 KB n=5
8 Correct 4 ms 1148 KB n=8
9 Correct 9 ms 1148 KB n=14
10 Correct 6 ms 1148 KB n=11
11 Correct 44 ms 5980 KB n=50000
12 Correct 44 ms 6056 KB n=50000
13 Correct 24 ms 6056 KB n=10
14 Correct 24 ms 6056 KB n=685
15 Correct 28 ms 6056 KB n=623
16 Correct 17 ms 6056 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 416 KB n=3
4 Correct 3 ms 420 KB n=4
5 Correct 2 ms 540 KB n=4
6 Correct 2 ms 632 KB n=2
7 Correct 2 ms 632 KB n=5
8 Correct 4 ms 1148 KB n=8
9 Correct 9 ms 1148 KB n=14
10 Correct 6 ms 1148 KB n=11
11 Correct 44 ms 5980 KB n=50000
12 Correct 44 ms 6056 KB n=50000
13 Correct 24 ms 6056 KB n=10
14 Correct 24 ms 6056 KB n=685
15 Correct 28 ms 6056 KB n=623
16 Correct 17 ms 6056 KB n=973
17 Incorrect 29 ms 6056 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2059 ms 104688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 416 KB n=3
4 Correct 3 ms 420 KB n=4
5 Correct 2 ms 540 KB n=4
6 Correct 2 ms 632 KB n=2
7 Correct 2 ms 632 KB n=5
8 Correct 4 ms 1148 KB n=8
9 Correct 9 ms 1148 KB n=14
10 Correct 6 ms 1148 KB n=11
11 Correct 44 ms 5980 KB n=50000
12 Correct 44 ms 6056 KB n=50000
13 Correct 24 ms 6056 KB n=10
14 Correct 24 ms 6056 KB n=685
15 Correct 28 ms 6056 KB n=623
16 Correct 17 ms 6056 KB n=973
17 Incorrect 29 ms 6056 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -