Submission #1049983

# Submission time Handle Problem Language Result Execution time Memory
1049983 2024-08-09T06:38:58 Z pan Restore Array (RMI19_restore) C++17
100 / 100
222 ms 1316 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;

ll const INF = 1e13;

ll n, q, l, r, k,v;
vector<pi> adj[5005];
vector<ll>  dist1, dist2;
void relax(vector<ll> & dist)
{
	for (ll idx=0; idx<=n; ++idx) for (pi u: adj[idx]) dist[u.f] = min(dist[u.f], dist[idx] + u.s);
}

int main()
{
	input2(n, q);
	for (ll i=0; i<=n; ++i)
	{
		if (i) adj[i].pb(mp(i-1, 1));
		if (i!=n) adj[i].pb(mp(i+1, 0));
	}
	while (q--)
	{
		input4(l, r, k, v);
		if (v) adj[l].pb(mp(r+1,l-r-2+k));
		else adj[r+1].pb(mp(l, r-l+1-k));
	}
	dist1.assign(n+1, INF);
	dist1[0] = 0;
	for (ll i=0; i<n; ++i) relax(dist1);
	dist2 = dist1;
	relax(dist2);
	if (dist2!=dist1) {print(-1LL, '\n'); exit(0);}
	for (ll i=1; i<=n; ++i) print(dist1[i-1] - dist1[i], ' ');

	return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
restore.cpp:49:2: note: in expansion of macro 'input2'
   49 |  input2(n, q);
      |  ^~~~~~
restore.cpp:15:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 | #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
restore.cpp:57:3: note: in expansion of macro 'input4'
   57 |   input4(l, r, k, v);
      |   ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 444 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 1112 KB Output is correct
2 Correct 202 ms 1240 KB Output is correct
3 Correct 213 ms 1224 KB Output is correct
4 Correct 189 ms 1112 KB Output is correct
5 Correct 187 ms 1116 KB Output is correct
6 Correct 191 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 1112 KB Output is correct
2 Correct 202 ms 1240 KB Output is correct
3 Correct 213 ms 1224 KB Output is correct
4 Correct 189 ms 1112 KB Output is correct
5 Correct 187 ms 1116 KB Output is correct
6 Correct 191 ms 1244 KB Output is correct
7 Correct 218 ms 1116 KB Output is correct
8 Correct 210 ms 1296 KB Output is correct
9 Correct 222 ms 1296 KB Output is correct
10 Correct 198 ms 1276 KB Output is correct
11 Correct 201 ms 1260 KB Output is correct
12 Correct 201 ms 1264 KB Output is correct
13 Correct 188 ms 1264 KB Output is correct
14 Correct 195 ms 1316 KB Output is correct
15 Correct 192 ms 1284 KB Output is correct
16 Correct 200 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 444 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 180 ms 1112 KB Output is correct
12 Correct 202 ms 1240 KB Output is correct
13 Correct 213 ms 1224 KB Output is correct
14 Correct 189 ms 1112 KB Output is correct
15 Correct 187 ms 1116 KB Output is correct
16 Correct 191 ms 1244 KB Output is correct
17 Correct 218 ms 1116 KB Output is correct
18 Correct 210 ms 1296 KB Output is correct
19 Correct 222 ms 1296 KB Output is correct
20 Correct 198 ms 1276 KB Output is correct
21 Correct 201 ms 1260 KB Output is correct
22 Correct 201 ms 1264 KB Output is correct
23 Correct 188 ms 1264 KB Output is correct
24 Correct 195 ms 1316 KB Output is correct
25 Correct 192 ms 1284 KB Output is correct
26 Correct 200 ms 1280 KB Output is correct
27 Correct 212 ms 1252 KB Output is correct
28 Correct 209 ms 1292 KB Output is correct
29 Correct 188 ms 1288 KB Output is correct
30 Correct 210 ms 1280 KB Output is correct
31 Correct 192 ms 1252 KB Output is correct
32 Correct 213 ms 1116 KB Output is correct
33 Correct 206 ms 1284 KB Output is correct
34 Correct 206 ms 1276 KB Output is correct
35 Correct 210 ms 1116 KB Output is correct
36 Correct 207 ms 1272 KB Output is correct