제출 #1232526

#제출 시각아이디문제언어결과실행 시간메모리
1232526peyman_sfRestore Array (RMI19_restore)C++20
0 / 100
572 ms98264 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll, ll> pll; const ll maxn = 5000, maxm = 1e4; const ll mod = 1e9 + 7; const ll inf = 2e9; #define TextIO ifstream fileIn("input.txt"); cin.rdbuf(fileIn.rdbuf()); ofstream fileOut("output.txt"); cout.rdbuf(fileOut.rdbuf()); #define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define print(x) for (auto i : x) cout << i << ' '; cout << endl #define out(x) {cout << x << endl; return;} #define all(x) (x).begin(), (x).end() #define pb push_back #define endl '\n' ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll pw(ll a, ll b, ll md = mod) {ll res = 1; b = max(b, 0ll); while(b) {if (b & 1){res = (a * res) % md;} a = (a * a) % md; b >>= 1;} return (res % md);} int n, m; struct {int u, v, w;} E[maxm]; int d[maxn][maxn]; void solve() { cin >> n >> m; for (int i = 1; i <= m; i++) { int l, r, k, x; cin >> l >> r >> k >> x; l++, r++; if (x == 1) E[i] = {r, l - 1, k - (r - l + 1) - 1}; else E[i] = {l - 1, r, (r - l + 1) - k}; } for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) d[i][j] = inf; for (int i = 0; i <= n; i++) d[0][i] = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) d[E[j].v][i] = min({d[E[j].v][i - 1], d[E[j].u][i - 1] + E[j].w, d[E[j].v][i]}); for (int i = 1; i <= n; i++) if (d[i][n] != d[i][n - 1]) out(-1); for (int i = 1; i <= n; i++) if (d[i][n - 1] == inf) d[i][n - 1] = d[i - 1][n - 1]; for (int i = 1; i <= n; i++) cout << d[i][n - 1] - d[i - 1][n - 1] << ' '; cout << endl; } int main() { FastIO ll t = 1; // cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...