QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627368 | #9345. Artful Paintings | guodong# | RE | 0ms | 4096kb | C++14 | 2.5kb | 2024-10-10 15:41:48 | 2024-10-10 15:41:48 |
Judging History
answer
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i = a; i <= b; ++i)
#define pb push_back
#define mp make_pair
const int N = 3020;
bool vis[N];
int cnt[N];
int dis[N];
int q[N];
class spfa{
private:
int n;
vector<vector<pair<int,int>>> To;
int head,tail;
public:
spfa(int siz = 0){
n = siz;
To.resize(n + 1);
head = 0,tail = -1;
For(i,0,n) {
cnt[i] = dis[i] = 0;
vis[i] = false;
}
}
void Add(int u,int v,int w){
To[u].pb(mp(v,w));
}
const int inf = 1e9;
int Spfa(){
For(i,0,n){
q[++tail] = i;
vis[i] = 1;
cnt[i]++;
}
while(head <= tail){
int u = q[head++];
if(cnt[u] > n+2)
return 1;
vis[u] = 0;
for(auto &arr : To[u]){
if(dis[arr.first] > dis[u] + arr.second ){
dis[arr.first] = dis[u] + arr.second;
if(!vis[arr.first]){
cnt[arr.first]++;
vis[arr.first] = 1;
q[++tail] = arr.first;
}
}
}
}
return 0;
}
};
inline int read(){
int x=0;
bool f=false;
char ch=getchar();
while(!isdigit(ch))f=ch=='-',ch=getchar();
while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return f?-x:x;
}
vector<pair<pair<int,int>,int>> Rule1;
vector<pair<pair<int,int>,int>> Rule2;
bool Judge(int n,int v){
spfa M = spfa(n + 1);
M.Add(0,n,v);
// sum[n] - sum[0] <= v;
M.Add(n,0,-v);
// sum[n] - sum[0] >= v;
For(i,1,n){
M.Add(i-1,i,1);
M.Add(i,i-1,0);
}
for(auto &tmp : Rule1){
int l = tmp.first.first;
int r = tmp.first.second;
int k = tmp.second;
// greater
M.Add(r,l-1,-k);
}
for(auto &tmp : Rule2){
int l = tmp.first.first;
int r = tmp.first.second;
int k = tmp.second;
// smaller
M.Add(l - 1,r,v - k);
}
if(M.Spfa())
return 0;
return 1;
}
signed main(){
#ifdef NICEGUODONG
freopen("data.in","r",stdin);
#endif
// ios::sync_with_stdio(false);
int T;
T =read();
while(T--){
int n,m1,m2;
Rule1.clear(),Rule2.clear();
n = read() , m1 = read(), m2 = read();
For(i,1,m1){
int l,r,k;
l = read() , r = read() , k = read();
auto tmp = mp(mp(l,r),k);
Rule1.pb(tmp);
}
For(i,1,m2){
int l,r,k;
l = read() , r = read() , k = read();
auto tmp = mp(mp(l,r),k);
Rule2.pb(tmp);
}
int l = 0,r = n,ans = 0;
while(l <= r){
int mid = (l + r) >> 1;
if(Judge(n,mid)){
r = mid - 1;
ans = mid;
}
else{
l = mid + 1;
}
}
printf("%d\n",ans);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4096kb
input:
1 3 1 1 1 2 1 2 2 1
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Runtime Error
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...