Submission #847114

#TimeUsernameProblemLanguageResultExecution timeMemory
847114CookieRestore Array (RMI19_restore)C++14
100 / 100
332 ms1304 KiB
#include<bits/stdc++.h> #define ll long long #define vt vector #define pb push_back #define pii pair<int, int> #define sz(v) (int)v.size() #define fi first #define se second using namespace std; const ll base = 107, mod = 1e9 + 7, mxv = 1e4 + 5, inf = 1e9; const int mxn = 5e3 + 5, N = 3e6 + 5; int n, m; int dis[mxn + 1]; bool vis[mxn + 1]; struct th{ int u, v, w; }; vt<th>edge; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < m; i++){ int l, r, k, v; cin >> l >> r >> k >> v; l++; r++; if(v == 1){ //pref[r] - k >= pref[l - 1] k = (r - l + 1) - k + 1; edge.pb({r, l - 1, -k}); //cout << r << " " << l - 1 << " " << -k << "\n"; }else{ k = (r - l + 1) - k; edge.pb({l - 1, r, k}); // cout << l - 1 << " " << r << " " << k << "\n"; } } for(int i = 1; i <= n; i++){ edge.pb({i, i - 1, 0}); edge.pb({i - 1, i, 1}); } for(int i = 1; i <= n; i++)dis[i] = inf; dis[0] = 0; bool no = 0; for(int i = 1; i <= n + 1; i++){ for(auto [u, v, w]: edge){ if(dis[v] > dis[u] + w){ dis[v] = dis[u] + w; if(i == n + 1)no = 1; } } } for(int i = 1; i <= n; i++){ if(dis[i] == inf)dis[i] = dis[i - 1]; } if(no)cout << -1 << "\n"; else{ for(int i = 1; i <= n; i++)cout << dis[i] - dis[i - 1] << " "; } }

Compilation message (stderr)

restore.cpp: In function 'int main()':
restore.cpp:44:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |         for(auto [u, v, w]: edge){
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...