#include <iostream>
using namespace std;
const int NMAX = 10005;
int v[NMAX], sp[NMAX], l[NMAX], r[NMAX], k[NMAX], value[NMAX];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, i, ns, b, subtask, ok;
cin >> n >> m;
subtask = 2;
for(i = 1; i <= m; i++)
{
cin >> l[i] >> r[i] >> k[i] >> value[i];
l[i]++;
r[i]++;
if(k[i] != 1)
subtask = 3;
}
/// Subtask #1
if(n <= 18 && m <= 200)
{
ns = (1 << n);
for(b = 0; b < ns; b++)
{
sp[0] = 0;
for(i = 1; i <= n; i++)
{
sp[i] = sp[i - 1];
if((1 << (i-1)) & b)
sp[i]++;
}
ok = 1;
for(i = 1; i <= m; i++)
{
if(value[i] == 0 && sp[r[i]] - sp[l[i] - 1] > r[i] - l[i] - k[i] + 1)
{
ok = 0;
break;
}
if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] < r[i] - l[i] - k[i] + 2)
{
ok = 0;
break;
}
}
if(ok)
{
for(i = 1; i <= n; i++)
{
cout << sp[i] - sp[i-1] << ' ';
}
return 0;
}
}
cout << "-1";
return 0;
}
/// Subtask #2
if(subtask == 2)
{
for(i = 1; i <= m; i++)
{
if(value[i] == 1)
{
sp[r[i] + 1]--;
sp[l[i]]++;
}
}
ok = 1;
for(i = 1; i <= m; i++)
{
if(value[i] == 0 && sp[r[i]] - sp[l[i] - 1] > r[i] - l[i] - k[i] + 1)
{
ok = 0;
break;
}
if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] < r[i] - l[i] - k[i] + 2)
{
ok = 0;
break;
}
}
if(!ok)
{
cout << "-1";
return 0;
}
for(i = 1; i <= n; i++)
{
sp[i] += sp[i-1];
if(sp[i])
cout << "1 ";
else
cout << "0 ";
}
return 0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
9 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
16 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
9 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
16 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Incorrect |
3 ms |
460 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |