結果
問題 | No.1341 真ん中を入れ替えて門松列 |
ユーザー | nmnmnmnmnmnmnm |
提出日時 | 2019-12-18 22:44:59 |
言語 | C++11 (gcc 11.4.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,053 bytes |
コンパイル時間 | 939 ms |
コンパイル使用メモリ | 99,928 KB |
実行使用メモリ | 636,704 KB |
最終ジャッジ日時 | 2024-09-21 12:00:19 |
合計ジャッジ時間 | 4,610 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,752 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 51 ms
6,656 KB |
testcase_07 | MLE | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
コンパイルメッセージ
main.cpp: In function ‘void ae(long long int, long long int, long long int, long long int)’: main.cpp:51:53: warning: narrowing conversion of ‘G[to].std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘long long int’ [-Wnarrowing] 51 | G[from].push_back((edge){to, cap, cost, G[to].size()}); | ~~~~~~~~~~^~ main.cpp:52:57: warning: narrowing conversion of ‘(G[from].std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘long long int’ [-Wnarrowing] 52 | G[to].push_back((edge){from, 0, -cost, G[from].size() - 1}); | ~~~~~~~~~~~~~~~^~~
ソースコード
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=b-1LL;i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define print(x) cout<<#x<<" = "<<x<<endl; #define MOD 1000000007 #define MAX_V 6010 #define INF 1000000000000000000LL typedef pair<long long, long long> P; struct edge{long long to, cap, cost, rev;}; vector<edge> G[MAX_V]; long long h[MAX_V]; long long dist[MAX_V]; long long prevv[MAX_V]; long long preve[MAX_V]; void ae(long long from, long long to, long long cap, long long cost){ G[from].push_back((edge){to, cap, cost, G[to].size()}); G[to].push_back((edge){from, 0, -cost, G[from].size() - 1}); } long long nmiCostFlow(long long s, long long t, long long f, long long V){ long long res = 0; memset(h,0,sizeof(h)); while(f > 0){ priority_queue<P, vector<P>, greater<P> > que; for(long long i = 0; i < V; i++){ dist[i] = INF; } dist[s] = 0; que.push(P(0,s)); while(!que.empty()){ P p = que.top(); que.pop(); long long v = p.second; if(dist[v] < p.first)continue; for(long long i = 0; i < G[v].size(); i++){ edge &e = G[v][i]; if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){ dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]; prevv[e.to] = v; preve[e.to] = i; que.push(P(dist[e.to], e.to)); } } } if(dist[t] == INF){ return -1; } for(long long v = 0; v < V; v++){ h[v] += dist[v]; } long long d = f; for(long long v = t; v != s; v = prevv[v]){ d = min(d, G[prevv[v]][preve[v]].cap); } f -= d; res += d * h[t]; for(long long v = t; v != s; v = prevv[v]){ edge &e = G[prevv[v]][preve[v]]; e.cap -= d; G[v][e.rev].cap += d; } } return res; } int main(){ ll n,m; cin>>n>>m; vector<ll> va,vb,vc; ll total = 0; rep(i,0,n){ ll a,b,c; cin>>a>>b>>c; va.pb(a); vb.pb(b); vc.pb(c); total += b + max(a,c); } rep(i,0,n){ ae(2*n,i,1,0); } rep(i,0,n){ ae(n+i,2*n+1,1,0); } rep(i,0,n){ rep(j,0,n){ if(vb[i]>max(va[j],vc[j])||vb[i]<min(va[j],vc[j])){ ae(i,n+j,1,min(vb[i],max(va[j],vc[j]))); } } } ll res = nmiCostFlow(2*n,2*n+1,n,2*n+2); if(res==-1){ cout << "NO" << endl; } else{ cout << "YES" << endl; if(total-res>=m){ cout << "KADOMATSU!" << endl; } else{ cout << "NO" << endl; } } return 0; }