제출 #1200713

#제출 시각아이디문제언어결과실행 시간메모리
1200713InvMOD도장 모으기 (JOI14_stamps)C++17
10 / 100
410 ms327680 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define eb emplace_back #define vi vector<int> #define pi pair<int,int> #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) template<class T> using upq = priority_queue<T, vector<T>, greater<T>>; template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());} template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());} #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define ROF(i, a, b) for(int i = (a); i >= (b); i--) #define sumof(x) accumulate(all(x), 0ll) #define dbg(x) "[" << #x " = " << (x) << "]" #define el "\n" using ll = long long; using ld = long double; template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);} template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);} const int N = 2e5 + 5, INF = 2e9; struct Node{ int u, mask, w; Node(int u = 0, int mask = 0, int w = 0): u(u), mask(mask), w(w) {} bool operator < (const Node& q) const{ return w > q.w; } }; int n, T, U[N], V[N], D[N], E[N], cnt_node; int upTrain[N], dwTrain[N], stamp[N]; vector<pair<int,int>> adj[N]; void Main() { cin >> n >> T; FOR(i, 1, n){ cin >> U[i] >> V[i] >> D[i] >> E[i]; } FOR(i, 1, n) stamp[i] = ++cnt_node; FOR(i, 0, n + 1) upTrain[i] = ++cnt_node; FOR(i, 1, n + 1) dwTrain[i] = ++cnt_node; FOR(i, 1, n + 1) adj[upTrain[i - 1]].eb(upTrain[i], T); ROF(i, n, 2) adj[dwTrain[i]].eb(dwTrain[i - 1], T); FOR(i, 1, n){ adj[upTrain[i]].eb(stamp[i], U[i]); adj[stamp[i]].eb(upTrain[i], V[i]); adj[dwTrain[i]].eb(stamp[i], D[i]); adj[stamp[i]].eb(dwTrain[i], E[i]); } priority_queue<Node> pq; vector<vi> dp(cnt_node + 1, vi((1 << n), INF)); pq.emplace(upTrain[0], 0, 0); dp[upTrain[0]][0] = 0; while(!pq.empty()){ Node e = pq.top(); pq.pop(); int x = e.u, mask = e.mask; for(auto [v, w] : adj[x]){ //cout << "Edge: " << v <<" " << x << " " << w << el; if(v <= n){ int nmask = mask | (1 << (v - 1)); if(ckmn(dp[v][nmask], dp[x][mask] + w)){ pq.emplace(v, nmask, dp[v][nmask]); } } else{ if(ckmn(dp[v][mask], dp[x][mask] + w)){ pq.emplace(v, mask, dp[v][mask]); } } } } cout << dp[upTrain[n + 1]][(1 << n) - 1] << el; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } int t = 1; while(t--) Main(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

stamps.cpp: In function 'int32_t main()':
stamps.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stamps.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...