답안 #338060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338060 2020-12-22T11:44:39 Z Nimbostratus Restore Array (RMI19_restore) C++17
38 / 100
67 ms 640 KB
#include <bits/stdc++.h>
#define mt make_tuple
using namespace std;
typedef long long ll;
const ll INF = 1e15;
int N,M;
string ans;
vector<tuple<int,int,int,int>> q; 

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	cin >> N >> M;
	for(int i=0;i<N;i++) ans += '2';
	q.resize(M);
	for(int i=0;i<M;i++)
	{
		int l,r,k,v;
		cin >> l >> r >> k >> v;
		q[i] = mt(l,r,k,v);
	}
	for(int i=0;i<M;i++)
	{
		int l,r,k,v;
		tie(l,r,k,v) = q[i];
		if(v == 1 and k == 1)
			for(int i=l;i<=r;i++)
				ans[i] = '1';
		if(v == 0 and k == r-l+1)
			for(int i=l;i<=r;i++)
				if(ans[i] == '1')
				{
					cout << -1 << endl;
					return 0;
				}
				else
					ans[i] = '0';
	}
	for(int i=0;i<M;i++)
	{
		int l,r,k,v;
		tie(l,r,k,v) = q[i];
		if(v == 0 and k == 1)
		{
			bool flag = 0;
			for(int i=l;i<=r;i++)
			{
				if(ans[i] == '0')
					flag = 1;
				if(ans[i] == '2' and !flag)
				{
					ans[i] = '0';
					flag = 1;
				}
			}
			if(!flag)
			{
				cout << -1 << endl;
				return 0;
			}
		}
		if(v == 1 and k == r-l+1)
		{
			bool flag = 0;
			for(int i=l;i<=r;i++)
			{
				if(ans[i] == '1') flag = 1;
				if(ans[i] == '2' and !flag)
				{
					ans[i] = '1';
					flag = 1;
				}
			}
			if(!flag)
			{
				cout << -1 << endl;
				return 0;
			}
		}
	}
	for(int i=0;i<N;i++)
		cout << (ans[i] == '2' ? '1' : ans[i]) << " ";
}

Compilation message

restore.cpp: In function 'int32_t main()':
restore.cpp:33:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   33 |   if(v == 0 and k == r-l+1)
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 620 KB Output is correct
2 Correct 47 ms 492 KB Output is correct
3 Correct 46 ms 492 KB Output is correct
4 Correct 50 ms 492 KB Output is correct
5 Correct 5 ms 492 KB Output is correct
6 Correct 16 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 620 KB Output is correct
2 Correct 47 ms 492 KB Output is correct
3 Correct 46 ms 492 KB Output is correct
4 Correct 50 ms 492 KB Output is correct
5 Correct 5 ms 492 KB Output is correct
6 Correct 16 ms 492 KB Output is correct
7 Correct 64 ms 492 KB Output is correct
8 Correct 66 ms 620 KB Output is correct
9 Correct 67 ms 620 KB Output is correct
10 Correct 62 ms 620 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 61 ms 620 KB Output is correct
14 Correct 18 ms 640 KB Output is correct
15 Correct 20 ms 620 KB Output is correct
16 Correct 25 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -