QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759620 | #9345. Artful Paintings | Scene# | WA | 236ms | 3920kb | C++14 | 2.8kb | 2024-11-18 10:32:40 | 2024-11-18 10:32:41 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#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<tuple<bool,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({0,i-1,0});
for(int i=1;i<=n;++i) G[i-1].pb({0,i,1});
int l, r, k;
for(int i = 1; i <= m1; i++){
G[r1[i]].pb({0,l1[i] - 1, -k1[i]});
}
for(int i = 1; i <= m2; i++){
G[l2[i]-1].pb({1,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({0,n,x});
// for(int i=0;i<=n;++i){
// q.push(i);
// vis[i]=1;
// }
while(!q.empty()){
int u = q.front(); q.pop();
num[u]++;
if(num[u]>n){
return 0;
}
vis[u]=0;
bool fl;
int v=0,w=0;
for(auto [fl,v,w] : G[u]){
if(fl) w=x-w;
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: 3744kb
input:
1 3 1 1 1 2 1 2 2 1
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 236ms
memory: 3920kb
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:
0
result:
wrong answer 1st lines differ - expected: '492', found: '0'