QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759637 | #9345. Artful Paintings | Scene# | TL | 792ms | 3920kb | C++14 | 2.6kb | 2024-11-18 10:43:06 | 2024-11-18 10:43:07 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
namespace IO {
#define gh getchar
inline int read(){char ch=gh();int x=0;bool t=0;while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();return t?-x:x;}
inline char getc(){char ch=gh();while(ch<'a'||ch>'z') ch=gh();return ch;}
inline void write(int x){if(x < 0){putchar('-');x = -x;}if(x > 9){write(x / 10);}putchar((x % 10 + '0'));}
}
using namespace IO;
using namespace std;
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
const int Maxn = 3010, mod = 1e9 + 7;
int n,m1,m2;
int f[Maxn]; vector<pair<int,int>> G[Maxn];
int l1[Maxn], r1[Maxn], k1[Maxn];
int l2[Maxn], r2[Maxn], k2[Maxn];
int num[Maxn];
bool check(int x){
for(int i=0;i<=n;++i) G[i].clear();
for(int i=1;i<=n;++i) G[i].pb({i-1,0});
for(int i=1;i<=n;++i) G[i-1].pb({i,1});
for(int i = 1; i <= m1; i++){
G[r1[i]].pb({l1[i] - 1, -k1[i]});
}
for(int i = 1; i <= m2; i++){
G[l2[i]-1].pb({r2[i],x-k2[i]});
}
queue<int> q;
bitset<Maxn> vis;
memset(f,0x3f,sizeof f);
memset(num,0,sizeof num);
f[0]=0;q.push(0);vis[0]=1;
G[0].pb({n,x});G[n].pb({0,-x});
while(!q.empty()){
int u = q.front(); q.pop();
num[u]++;
if(num[u]>n){
return 0;
}
vis[u]=0;
int v=0,w=0;
for(auto [v,w] : G[u]){
if(f[v]>f[u]+w){
f[v]=f[u]+w;
if(!vis[v]){
vis[v]=1;
q.push(v);
}
}
}
}
return 1;
}
void work(){
n = read(), m1 = read(), m2 = read();
for(int i = 1; i <= m1; i++){
l1[i] = read(), r1[i] = read(), k1[i] = read();
}
for(int i = 1; i <= m2; i++){
l2[i] = read(), r2[i] = read(), k2[i] = read();
}
int l = 0, r = n;
int ans=0;
while(l <= r){
int mid = (l + r) >> 1;
if(check(mid)){
r = mid - 1, ans = mid;
}else l = mid + 1;
}
cout<< ans <<endl;
}
signed main(){
int t = read();
while(t--){
work();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
1 3 1 1 1 2 1 2 2 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 104ms
memory: 3760kb
input:
1 1000 500 500 479 860 170 73 939 25 363 772 30 185 584 89 326 482 10 784 949 23 384 740 114 233 693 45 167 724 211 217 436 95 46 701 153 138 585 67 321 388 11 114 890 194 407 854 74 438 845 117 9 718 259 393 576 35 182 707 257 451 766 136 150 382 31 468 785 40 202 490 46 326 815 59 272 441 77 123 8...
output:
492
result:
ok single line: '492'
Test #3:
score: 0
Accepted
time: 514ms
memory: 3868kb
input:
1 3000 1000 1000 497 660 17 36 1021 195 2363 2786 90 1202 1218 5 1443 1627 76 2398 2642 59 1614 2082 296 2241 2286 3 360 2995 1736 2163 2566 245 526 990 103 916 1774 392 523 762 38 140 1912 187 472 2868 33 945 1039 60 739 2666 99 865 1440 143 1603 2378 97 672 1202 322 75 1406 367 1483 2534 397 1875 ...
output:
1977
result:
ok single line: '1977'
Test #4:
score: 0
Accepted
time: 659ms
memory: 3920kb
input:
1 3000 3000 3000 1277 1792 170 1578 1791 2 880 1814 109 2391 2691 185 385 1470 379 882 1802 315 1104 1616 310 121 1609 358 730 1880 729 1199 2068 535 666 2098 210 1642 1765 64 11 1567 437 188 2911 1398 2255 2257 0 2123 2428 32 797 1981 566 463 2583 125 517 2603 62 35 820 10 1446 2327 142 260 2997 92...
output:
1992
result:
ok single line: '1992'
Test #5:
score: 0
Accepted
time: 138ms
memory: 3724kb
input:
3 1000 500 500 591 664 15 735 959 57 537 897 80 744 964 57 666 917 58 121 545 83 352 374 2 300 377 20 140 889 156 658 905 59 395 595 36 675 784 22 593 967 86 435 620 34 478 846 75 46 680 124 81 882 165 20 471 87 279 393 27 693 716 4 125 734 121 154 921 160 109 691 114 3 802 160 743 833 19 216 236 5 ...
output:
204 469 627
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
100 6 0 1 5 5 5 6 8 2 1 2 0 2 4 2 2 5 2 2 5 2 3 6 3 3 5 2 4 6 2 2 2 0 3 4 1 2 4 1 12 7 2 3 7 2 4 7 1 5 10 5 1 7 6 2 3 0 6 9 3 1 5 2 4 9 6 3 11 2 18 1 6 2 10 5 3 17 1 3 11 4 10 18 5 7 18 2 1 13 2 11 18 6 15 4 10 9 15 1 5 11 3 6 14 2 4 12 3 5 13 0 8 9 1 1 4 3 4 5 2 14 14 3 9 15 2 2 4 3 10 14 3 3 6 2 6...
output:
5 3 10 8 3 11 2 12 0 2 7 0 0 1 5 0 0 5 1 11 12 1 2 1 5 1 7 2 2 1 2 3 1 0 9 1 2 0 1 7 2 1 2 5 3 0 8 12 2 2 0 1 0 6 4 1 0 1 9 2 4 4 5 12 3 6 2 4 1 17 1 5 2 7 0 2 4 1 6 0 6 6 4 5 14 2 5 3 0 4 1 1 1 8 10 13 2 0 8 2
result:
ok 100 lines
Test #7:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
100 5 9 3 1 4 3 3 5 3 1 2 1 2 3 2 4 5 2 3 5 3 1 3 2 1 4 3 3 3 1 4 5 2 4 4 3 3 5 1 18 4 0 13 18 0 1 1 1 3 16 1 4 5 1 16 2 7 2 12 7 3 14 7 2 10 3 3 7 6 6 15 3 2 10 3 5 16 3 13 14 8 4 14 3 18 5 10 4 11 0 5 6 0 7 8 0 8 12 1 12 15 0 5 11 0 4 11 0 2 4 1 4 13 0 1 17 0 6 16 0 1 17 0 1 13 0 5 12 0 1 12 0 13 ...
output:
4 2 9 1 12 0 3 1 6 3 0 9 6 0 13 10 1 0 1 2 9 14 1 3 3 5 1 0 14 1 11 11 2 4 2 0 11 4 1 14 0 2 3 2 4 3 2 2 0 10 6 0 1 3 12 7 3 5 12 1 2 0 3 0 4 13 1 3 7 9 7 1 2 13 14 2 10 10 0 0 1 3 4 2 0 0 1 8 0 1 10 2 5 14 7 11 2 8 2 1
result:
ok 100 lines
Test #8:
score: 0
Accepted
time: 3ms
memory: 3880kb
input:
10 67 28 17 33 53 19 32 42 9 5 36 29 11 16 6 1 57 53 12 13 2 53 57 5 43 64 21 20 41 19 42 51 10 10 10 1 24 25 2 3 15 12 5 67 58 40 41 2 8 28 21 1 17 16 34 61 25 46 59 13 21 45 22 11 51 38 7 25 19 8 8 1 29 34 4 25 63 35 60 67 8 10 45 33 7 8 2 3 50 18 3 57 11 50 67 45 4 64 6 61 64 58 54 57 58 2 13 51 ...
output:
62 0 31 10 22 16 100 6 48 20
result:
ok 10 lines
Test #9:
score: 0
Accepted
time: 792ms
memory: 3840kb
input:
1 3000 3000 3000 1422 2281 584 1820 2540 304 464 2049 641 1991 2485 89 2029 2185 83 235 812 385 283 2935 760 558 1776 472 176 2540 1558 1507 2713 599 2181 2889 456 236 2165 867 406 913 354 496 2752 1627 1173 1382 156 498 2705 828 2489 2975 298 1817 2634 293 2571 2848 133 737 1938 307 688 2795 1565 1...
output:
2362
result:
ok single line: '2362'
Test #10:
score: -100
Time Limit Exceeded
input:
1 3000 3000 3000 595 727 57 2704 2779 37 556 1280 196 363 2067 970 1177 1260 37 1650 2801 478 1861 1886 11 96 690 276 2139 2902 550 1997 2105 19 1376 2711 269 18 2293 837 2003 2931 67 581 2210 468 1786 2540 667 1496 2164 650 1872 2606 23 1415 2296 450 337 2544 1861 2348 2997 567 101 1097 393 150 177...