-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVa-11926.cpp
More file actions
92 lines (60 loc) · 1.78 KB
/
UVa-11926.cpp
File metadata and controls
92 lines (60 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h> // here we have all the STL we need, including istringstream and ostringstream
#define ALL(x) x.begin(), x.end()
#define FAST std::cin.tie(0); ios::sync_with_stdio(false); std::cout.tie(0);
using namespace std;
bool has_conflict(int& n, int& m, vector<int>& s, vector<int>& e, vector<int>& T);
bitset<1000000> b;
/* UVa 11926, Multitasking (bitset problem) */
int main(void) {
FAST
b.reset();
int n, m;
while (cin >> n >> m, n || m) {
bool conflict = false;
vector<int> s(n + m);
vector<int> e(n+m);
vector<int> T(m);
for (int i = 0; i < n; i++) {
cin >> s[i] >> e[i];
}
for (int i = n; i < n+m; i++) {
cin >> s[i] >> e[i] >> T[i];
}
if (has_conflict(n, m, s, e, T)) cout << "CONFLICT\n";
else cout << "NO CONFLICT\n";
}
return 0;
}
bool has_conflict(int& n, int& m, vector<int>& s, vector<int>& e, vector<int>& T) {
// one time (no period)
for (int i = 0; i < n; i++) {
int start = s[i];
int end = e[i];
for (int j = start; j < end; j++) {
if (b.test(j))
return true;
b.set(j);
}
}
// periodics
for (int i = n; i < n+m; i++) {
int start = s[i];
int end = e[i];
int period = T[n+i];
while (end < 1000000) {
for (int j = start; j < end; j++) {
if (b.test(j))
return true;
b.set(j);
}
end = min(end + period, 1000000);
start = start + period;
}
}
return false;
}