Submission #34311054
Source Code Expand
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <cmath> #include <queue> using namespace std; #define mp make_pair #define pb push_back #define ll long long struct Rule { int trigger; int limit; int who; bool operator<(const Rule &other) const { return trigger < other.trigger; } }; int n, m, k, p, x, q, y; vector<vector<Rule>> rules; vector<int> v; vector<int> executed; queue< pair<int, int> > que; void advance(int pos) { while (executed[pos] < rules[pos].size() && rules[pos][executed[pos]].trigger < v[pos]) { Rule rule = rules[pos][executed[pos]++]; if (v[rule.who] < rule.limit + 1) { v[rule.who] = rule.limit + 1; que.push(make_pair(v[rule.who], rule.who)); } } int aux = executed[pos]; while (aux < rules[pos].size() && rules[pos][aux].trigger == v[pos]) { Rule rule = rules[pos][aux++]; if (v[rule.who] < rule.limit) { v[rule.who] = rule.limit; que.push(make_pair(v[rule.who], rule.who)); } } } void check_rule(int pos, Rule rule) { int p, q, x, y; bool bad = false; p = pos; q = rule.who; x = rule.trigger; y = rule.limit; bad |= v[p] < x && !(v[q] < y); bad |= v[p] == x && !(v[q] == y); bad |= v[p] > x && !(v[q] > y); if (bad) { cout << -1; exit(0); } } int main() { cin >> n >> m >> k; rules.resize(n); v.resize(n); executed.resize(n); for (int i = 0; i < k; i++) { cin >> p >> x >> q >> y; p--; x--; q--; y--; rules[p].push_back({ .trigger = x, .limit = y, .who = q }); rules[q].push_back({ .trigger = y, .limit = x, .who = p }); } for (int i = 0; i < n; i++) sort(rules[i].begin(), rules[i].end()); for (int i = 0; i < n; i++) { v[i] = 0; executed[i] = 0; que.push(make_pair(0, i)); } while (!que.empty()) { pair<int, int> curr = que.front(); que.pop(); int val = curr.first; int pos = curr.second; if (v[pos] != val) continue; advance(pos); } ll ans = n; for (int i = 0; i < n; i++) { ans += v[i]; if (v[i] >= m) { cout << -1; return 0; } for (Rule rule: rules[i]) check_rule(i, rule); } cout << ans; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - >=< |
User | atatomir |
Language | C++ (GCC 9.2.1) |
Score | 800 |
Code Size | 2418 Byte |
Status | AC |
Exec Time | 243 ms |
Memory | 19600 KiB |
Compile Error
./Main.cpp: In function ‘void advance(int)’: ./Main.cpp:32:24: warning: comparison of integer expressions of different signedness: ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} and ‘std::vector<Rule>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 32 | while (executed[pos] < rules[pos].size() && rules[pos][executed[pos]].trigger < v[pos]) { ./Main.cpp:42:14: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<Rule>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 42 | while (aux < rules[pos].size() && rules[pos][aux].trigger == v[pos]) { | ~~~~^~~~~~~~~~~~~~~~~~~
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 800 / 800 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt, test_72.txt, test_73.txt, test_74.txt, test_75.txt, test_76.txt, test_77.txt, test_78.txt, test_79.txt, test_80.txt, test_81.txt, test_82.txt, test_83.txt, test_84.txt, test_85.txt, test_86.txt, test_87.txt, test_88.txt, test_89.txt, test_90.txt, test_91.txt, test_92.txt, test_93.txt, test_94.txt, test_95.txt, test_96.txt, test_97.txt, test_98.txt, test_99.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 7 ms | 3504 KiB |
example_01.txt | AC | 2 ms | 3448 KiB |
example_02.txt | AC | 2 ms | 3444 KiB |
test_00.txt | AC | 145 ms | 12280 KiB |
test_01.txt | AC | 165 ms | 15580 KiB |
test_02.txt | AC | 70 ms | 7752 KiB |
test_03.txt | AC | 121 ms | 13248 KiB |
test_04.txt | AC | 44 ms | 7316 KiB |
test_05.txt | AC | 73 ms | 13152 KiB |
test_06.txt | AC | 102 ms | 11304 KiB |
test_07.txt | AC | 152 ms | 10084 KiB |
test_08.txt | AC | 32 ms | 5828 KiB |
test_09.txt | AC | 154 ms | 12364 KiB |
test_10.txt | AC | 57 ms | 5816 KiB |
test_11.txt | AC | 164 ms | 16716 KiB |
test_12.txt | AC | 155 ms | 15524 KiB |
test_13.txt | AC | 112 ms | 14672 KiB |
test_14.txt | AC | 28 ms | 6240 KiB |
test_15.txt | AC | 49 ms | 5304 KiB |
test_16.txt | AC | 53 ms | 5648 KiB |
test_17.txt | AC | 149 ms | 8336 KiB |
test_18.txt | AC | 19 ms | 3908 KiB |
test_19.txt | AC | 46 ms | 4540 KiB |
test_20.txt | AC | 188 ms | 7352 KiB |
test_21.txt | AC | 136 ms | 7888 KiB |
test_22.txt | AC | 108 ms | 6708 KiB |
test_23.txt | AC | 137 ms | 7240 KiB |
test_24.txt | AC | 22 ms | 4112 KiB |
test_25.txt | AC | 117 ms | 6792 KiB |
test_26.txt | AC | 43 ms | 4800 KiB |
test_27.txt | AC | 98 ms | 7304 KiB |
test_28.txt | AC | 64 ms | 5184 KiB |
test_29.txt | AC | 38 ms | 4596 KiB |
test_30.txt | AC | 215 ms | 19100 KiB |
test_31.txt | AC | 217 ms | 19180 KiB |
test_32.txt | AC | 214 ms | 19100 KiB |
test_33.txt | AC | 219 ms | 19224 KiB |
test_34.txt | AC | 225 ms | 19156 KiB |
test_35.txt | AC | 220 ms | 19176 KiB |
test_36.txt | AC | 209 ms | 19232 KiB |
test_37.txt | AC | 215 ms | 19276 KiB |
test_38.txt | AC | 213 ms | 19188 KiB |
test_39.txt | AC | 222 ms | 19156 KiB |
test_40.txt | AC | 222 ms | 19240 KiB |
test_41.txt | AC | 219 ms | 19188 KiB |
test_42.txt | AC | 216 ms | 19332 KiB |
test_43.txt | AC | 216 ms | 19224 KiB |
test_44.txt | AC | 216 ms | 19184 KiB |
test_45.txt | AC | 133 ms | 15752 KiB |
test_46.txt | AC | 56 ms | 5988 KiB |
test_47.txt | AC | 151 ms | 10724 KiB |
test_48.txt | AC | 147 ms | 12820 KiB |
test_49.txt | AC | 144 ms | 12560 KiB |
test_50.txt | AC | 213 ms | 16844 KiB |
test_51.txt | AC | 174 ms | 14796 KiB |
test_52.txt | AC | 34 ms | 6288 KiB |
test_53.txt | AC | 205 ms | 16276 KiB |
test_54.txt | AC | 125 ms | 14792 KiB |
test_55.txt | AC | 73 ms | 10388 KiB |
test_56.txt | AC | 214 ms | 15812 KiB |
test_57.txt | AC | 163 ms | 13636 KiB |
test_58.txt | AC | 135 ms | 10780 KiB |
test_59.txt | AC | 151 ms | 11464 KiB |
test_60.txt | AC | 145 ms | 13952 KiB |
test_61.txt | AC | 28 ms | 10292 KiB |
test_62.txt | AC | 141 ms | 15000 KiB |
test_63.txt | AC | 78 ms | 12100 KiB |
test_64.txt | AC | 37 ms | 6392 KiB |
test_65.txt | AC | 210 ms | 16976 KiB |
test_66.txt | AC | 128 ms | 9540 KiB |
test_67.txt | AC | 194 ms | 16936 KiB |
test_68.txt | AC | 174 ms | 14208 KiB |
test_69.txt | AC | 162 ms | 12972 KiB |
test_70.txt | AC | 193 ms | 13416 KiB |
test_71.txt | AC | 171 ms | 10784 KiB |
test_72.txt | AC | 213 ms | 15992 KiB |
test_73.txt | AC | 200 ms | 16812 KiB |
test_74.txt | AC | 130 ms | 11948 KiB |
test_75.txt | AC | 226 ms | 19384 KiB |
test_76.txt | AC | 225 ms | 19500 KiB |
test_77.txt | AC | 225 ms | 19508 KiB |
test_78.txt | AC | 229 ms | 19488 KiB |
test_79.txt | AC | 225 ms | 19492 KiB |
test_80.txt | AC | 237 ms | 19508 KiB |
test_81.txt | AC | 229 ms | 19600 KiB |
test_82.txt | AC | 224 ms | 19452 KiB |
test_83.txt | AC | 223 ms | 19448 KiB |
test_84.txt | AC | 227 ms | 19424 KiB |
test_85.txt | AC | 207 ms | 15628 KiB |
test_86.txt | AC | 210 ms | 15572 KiB |
test_87.txt | AC | 205 ms | 15636 KiB |
test_88.txt | AC | 203 ms | 15556 KiB |
test_89.txt | AC | 201 ms | 15516 KiB |
test_90.txt | AC | 188 ms | 15520 KiB |
test_91.txt | AC | 185 ms | 15624 KiB |
test_92.txt | AC | 179 ms | 15512 KiB |
test_93.txt | AC | 194 ms | 15564 KiB |
test_94.txt | AC | 184 ms | 15512 KiB |
test_95.txt | AC | 233 ms | 17256 KiB |
test_96.txt | AC | 227 ms | 17312 KiB |
test_97.txt | AC | 223 ms | 17272 KiB |
test_98.txt | AC | 243 ms | 17340 KiB |
test_99.txt | AC | 227 ms | 17488 KiB |