QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625550#9345. Artful Paintingsucup-team4352#RE 1ms3640kbC++232.5kb2024-10-09 19:46:452024-10-09 19:46:46

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 19:46:46]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3640kb
  • [2024-10-09 19:46:45]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
using i64 = long long;
const int maxn = 3'000;
const int maxm = 10'000;
struct edge {
  int v, w, next;
} e[maxm + 5];
int head[maxn + 5], tot[maxn + 5], vis[maxn + 5], cnt, n, m;
i64 dis[maxn + 5];
void addedge(int u, int v, int w) {
  e[++cnt].v = v;
  e[cnt].w = w;
  e[cnt].next = head[u];
  head[u] = cnt;
//   if(w>=0)cout<<"a"<<u<<"+"<<""<<w<<"<=a"<<v<<"\n";else cout<<"a"<<u<<"<=a"<<v<<"+"<<abs(w)<<"\n";
}
bool spfa(int s) {
  queue<int> q;
  memset(dis, 63, (n+3)*sizeof(ll));
  memset(tot, 0, (n+3)*sizeof(int));
  dis[s] = 0, vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].v;
      if (dis[v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        if (!vis[v]) {
          vis[v] = 1, tot[v]++;
          if (tot[v] == n + 1) return false;  // 注意添加了一个超级源点
          q.push(v);
        }
      }
    }
  }
  return true;
}
struct node1{
	int l,r,k;
};
node1 read(){
	int l,r,k;
	cin>>l>>r>>k;
	return{l,r,k};
}
vector<node1>q1,q2;
/*
u v y
xv-xu<=y
xv<=xu+y
*/
bool solvequery(int x){
	memset(head, 0, (n+3)*sizeof(int));
	for(int i=2;i<=n+1;i++){
		addedge(i-1,i,1);
		addedge(i,i-1,0);
	}
	for (int i = 1; i <= n+1; i++) addedge(0, i, 0);
	addedge(1,n+1,x);
	addedge(n+1,1,-x);
	for(auto u:q1){
		addedge(u.r+1,u.l-1+1,-u.k);
	}
	for(auto u:q2){
		addedge(u.l-1+1,u.r+1,x-u.k);
	}
	// exit(0);
	return spfa(0);
}
void solve(){
	int m1,m2;
	cin>>n>>m1>>m2;
	q1.clear();
	q2.clear();
	int mn=0;
	for(int i=1;i<=m1;i++){
		q1.push_back(read());
		mn=max(mn,q1.back().k);
	}
	for(int i=1;i<=m2;i++){
		q2.push_back(read());
		mn=max(mn,q2.back().k);
	}
	int l=mn,r=n;
	while(l<r){
		int mid=l+r-1>>1;
		if(solvequery(mid))r=mid;
		else l=mid+1;
		// for(int i=1;i<=n+1;i++)cout<<dis[i]<<" ";cout<<"\n";
	}
	cout<<l<<"\n";
}
int main() {
//   cin >> n >> m;
//   for (int i = 1; i <= n; i++) addedge(0, i, 0);
//   for (int i = 1; i <= m; i++) {
//     int v, u, w;
//     cin >> v >> u >> w;
//     addedge(u, v, w);
//   }
//   if (!spfa(0))
//     cout << "NO" << endl;
//   else
//     for (int i = 1; i <= n; i++) cout << dis[i] << ' ';
//   return 0;
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	cin>>t;
	while(t--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

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...

output:


result: