답안 #217733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217733 2020-03-30T14:45:12 Z _7_7_ 치료 계획 (JOI20_treatment) C++14
39 / 100
3000 ms 268048 KB
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef unsigned long long ull;
typedef pair < int, int > pii;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


ll d[N];
vi xx, toDel;
int n, m, x[N];
set < pair < ll, int > > q, T[N << 2][2];


struct project {
    ll c;
	int t, l, r;
} a[N];

void add (int pos, int lvl, pii x, int v = 1, int tl = 0, int tr = m - 1) {
	T[v][lvl].insert(x);
	if (tl == tr)
		return;

	int tm = (tl + tr) >> 1;
	if (pos <= tm)
		add(pos, lvl, x, v << 1, tl, tm);
	else
		add(pos, lvl, x, v << 1 | 1, tm + 1, tr);
}

void del (int pos, int lvl, pii x, int v = 1, int tl = 0, int tr = m - 1) {
	T[v][lvl].erase(x);
	if (tl == tr)
		return;
	
	int tm = (tl + tr) >> 1;
	if (pos <= tm)
		del(pos, lvl, x, v << 1, tl, tm);
	else
		del(pos, lvl, x, v << 1 | 1, tm + 1, tr);
}

void f (int l, int r, int lvl, int X, ll Y, int v = 1, int tl = 0, int tr = m - 1) {
	if (l > r || l > tr || tl > r)
		return;

	if (l <= tl && tr <= r) {		
		auto it = T[v][lvl].begin();            
		while (it != T[v][lvl].end()  && it->f <= X) {
			toDel.pb(it->s);
			++it;
		}

		while (sz(toDel)) {
		    int i = toDel.back();
		    toDel.ppb();
		    
			d[i] = Y + a[i].c;
			q.insert({d[i], i});
			del(x[i], 0, {a[i].l + a[i].t, i});
			del(x[i], 1, {a[i].l - a[i].t, i});
		}
		return;
	}

	int tm = (tl + tr) >> 1;
	f(l, r, lvl, X, Y, v << 1, tl, tm);
	f(l, r, lvl, X, Y, v << 1 | 1, tm + 1, tr);
}
	


main () {
    memset(d, -1, sizeof(d));
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d%d%lld", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
		++a[i].r;
		xx.pb(a[i].t);
	}
	
	sort(all(xx));
	xx.resize(unique(all(xx)) - xx.begin());
	
    for (int i = 1; i <= m; ++i) {
        x[i] = lower_bound(all(xx), a[i].t) - xx.begin();
        if (a[i].l == 1) {
            d[i] = a[i].c;
            q.insert({d[i], i});
        } else {
            add(x[i], 0, {a[i].l + a[i].t, i});
            add(x[i], 1, {a[i].l - a[i].t, i});
        }        
    }


	while (sz(q)) {
		int v = q.begin()->s;
		q.erase(q.begin());
		
		f(x[v], m - 1, 0, a[v].r + a[v].t, d[v]);
		f(0, x[v], 1, a[v].r - a[v].t, d[v]);
	}
	
		
	ll mn = INF;	
	for (int i = 1; i <= m; ++i)
		if (a[i].r == n + 1 && d[i] > -1)
			mn = min(mn, d[i]);

	if (mn == INF)
		mn = -1;
	printf("%lld\n", mn);
}




Compilation message

treatment.cpp:104:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
treatment.cpp: In function 'int main()':
treatment.cpp:106:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%lld", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1220 ms 267288 KB Output is correct
2 Correct 1339 ms 267376 KB Output is correct
3 Correct 1071 ms 212784 KB Output is correct
4 Correct 1080 ms 212720 KB Output is correct
5 Correct 1276 ms 265120 KB Output is correct
6 Correct 1174 ms 267248 KB Output is correct
7 Correct 1069 ms 267372 KB Output is correct
8 Correct 1269 ms 265248 KB Output is correct
9 Correct 1208 ms 267160 KB Output is correct
10 Correct 1132 ms 267376 KB Output is correct
11 Correct 1307 ms 268048 KB Output is correct
12 Correct 1328 ms 267648 KB Output is correct
13 Correct 1336 ms 267376 KB Output is correct
14 Correct 1338 ms 266996 KB Output is correct
15 Correct 1240 ms 267380 KB Output is correct
16 Correct 1275 ms 267376 KB Output is correct
17 Correct 1273 ms 267376 KB Output is correct
18 Correct 1362 ms 268016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 38656 KB Output is correct
2 Correct 26 ms 38656 KB Output is correct
3 Correct 25 ms 38648 KB Output is correct
4 Correct 25 ms 38656 KB Output is correct
5 Correct 30 ms 38784 KB Output is correct
6 Correct 30 ms 38656 KB Output is correct
7 Correct 25 ms 38656 KB Output is correct
8 Correct 25 ms 38656 KB Output is correct
9 Correct 26 ms 38648 KB Output is correct
10 Correct 25 ms 38656 KB Output is correct
11 Correct 25 ms 38784 KB Output is correct
12 Correct 25 ms 38656 KB Output is correct
13 Correct 25 ms 38656 KB Output is correct
14 Correct 26 ms 38656 KB Output is correct
15 Correct 26 ms 38656 KB Output is correct
16 Correct 25 ms 38656 KB Output is correct
17 Correct 27 ms 38784 KB Output is correct
18 Correct 25 ms 38656 KB Output is correct
19 Correct 25 ms 38656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 38656 KB Output is correct
2 Correct 26 ms 38656 KB Output is correct
3 Correct 25 ms 38648 KB Output is correct
4 Correct 25 ms 38656 KB Output is correct
5 Correct 30 ms 38784 KB Output is correct
6 Correct 30 ms 38656 KB Output is correct
7 Correct 25 ms 38656 KB Output is correct
8 Correct 25 ms 38656 KB Output is correct
9 Correct 26 ms 38648 KB Output is correct
10 Correct 25 ms 38656 KB Output is correct
11 Correct 25 ms 38784 KB Output is correct
12 Correct 25 ms 38656 KB Output is correct
13 Correct 25 ms 38656 KB Output is correct
14 Correct 26 ms 38656 KB Output is correct
15 Correct 26 ms 38656 KB Output is correct
16 Correct 25 ms 38656 KB Output is correct
17 Correct 27 ms 38784 KB Output is correct
18 Correct 25 ms 38656 KB Output is correct
19 Correct 25 ms 38656 KB Output is correct
20 Correct 61 ms 45176 KB Output is correct
21 Correct 63 ms 45176 KB Output is correct
22 Correct 75 ms 47224 KB Output is correct
23 Correct 80 ms 47352 KB Output is correct
24 Correct 71 ms 45816 KB Output is correct
25 Correct 71 ms 47080 KB Output is correct
26 Correct 69 ms 47224 KB Output is correct
27 Correct 69 ms 47224 KB Output is correct
28 Correct 68 ms 45816 KB Output is correct
29 Correct 70 ms 47096 KB Output is correct
30 Correct 63 ms 47224 KB Output is correct
31 Correct 64 ms 47224 KB Output is correct
32 Correct 83 ms 47224 KB Output is correct
33 Correct 82 ms 47224 KB Output is correct
34 Correct 83 ms 47224 KB Output is correct
35 Correct 81 ms 47224 KB Output is correct
36 Correct 81 ms 47224 KB Output is correct
37 Correct 79 ms 47224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1220 ms 267288 KB Output is correct
2 Correct 1339 ms 267376 KB Output is correct
3 Correct 1071 ms 212784 KB Output is correct
4 Correct 1080 ms 212720 KB Output is correct
5 Correct 1276 ms 265120 KB Output is correct
6 Correct 1174 ms 267248 KB Output is correct
7 Correct 1069 ms 267372 KB Output is correct
8 Correct 1269 ms 265248 KB Output is correct
9 Correct 1208 ms 267160 KB Output is correct
10 Correct 1132 ms 267376 KB Output is correct
11 Correct 1307 ms 268048 KB Output is correct
12 Correct 1328 ms 267648 KB Output is correct
13 Correct 1336 ms 267376 KB Output is correct
14 Correct 1338 ms 266996 KB Output is correct
15 Correct 1240 ms 267380 KB Output is correct
16 Correct 1275 ms 267376 KB Output is correct
17 Correct 1273 ms 267376 KB Output is correct
18 Correct 1362 ms 268016 KB Output is correct
19 Correct 28 ms 38656 KB Output is correct
20 Correct 26 ms 38656 KB Output is correct
21 Correct 25 ms 38648 KB Output is correct
22 Correct 25 ms 38656 KB Output is correct
23 Correct 30 ms 38784 KB Output is correct
24 Correct 30 ms 38656 KB Output is correct
25 Correct 25 ms 38656 KB Output is correct
26 Correct 25 ms 38656 KB Output is correct
27 Correct 26 ms 38648 KB Output is correct
28 Correct 25 ms 38656 KB Output is correct
29 Correct 25 ms 38784 KB Output is correct
30 Correct 25 ms 38656 KB Output is correct
31 Correct 25 ms 38656 KB Output is correct
32 Correct 26 ms 38656 KB Output is correct
33 Correct 26 ms 38656 KB Output is correct
34 Correct 25 ms 38656 KB Output is correct
35 Correct 27 ms 38784 KB Output is correct
36 Correct 25 ms 38656 KB Output is correct
37 Correct 25 ms 38656 KB Output is correct
38 Correct 61 ms 45176 KB Output is correct
39 Correct 63 ms 45176 KB Output is correct
40 Correct 75 ms 47224 KB Output is correct
41 Correct 80 ms 47352 KB Output is correct
42 Correct 71 ms 45816 KB Output is correct
43 Correct 71 ms 47080 KB Output is correct
44 Correct 69 ms 47224 KB Output is correct
45 Correct 69 ms 47224 KB Output is correct
46 Correct 68 ms 45816 KB Output is correct
47 Correct 70 ms 47096 KB Output is correct
48 Correct 63 ms 47224 KB Output is correct
49 Correct 64 ms 47224 KB Output is correct
50 Correct 83 ms 47224 KB Output is correct
51 Correct 82 ms 47224 KB Output is correct
52 Correct 83 ms 47224 KB Output is correct
53 Correct 81 ms 47224 KB Output is correct
54 Correct 81 ms 47224 KB Output is correct
55 Correct 79 ms 47224 KB Output is correct
56 Correct 1797 ms 209648 KB Output is correct
57 Correct 1787 ms 209824 KB Output is correct
58 Correct 1978 ms 262512 KB Output is correct
59 Correct 1971 ms 262644 KB Output is correct
60 Correct 2294 ms 263568 KB Output is correct
61 Correct 1961 ms 262584 KB Output is correct
62 Correct 1762 ms 209620 KB Output is correct
63 Correct 1723 ms 263444 KB Output is correct
64 Correct 1734 ms 263400 KB Output is correct
65 Correct 1413 ms 267404 KB Output is correct
66 Correct 2245 ms 263456 KB Output is correct
67 Correct 2606 ms 261496 KB Output is correct
68 Correct 2163 ms 263280 KB Output is correct
69 Correct 1817 ms 263408 KB Output is correct
70 Correct 2946 ms 261744 KB Output is correct
71 Correct 2211 ms 263296 KB Output is correct
72 Correct 1755 ms 263408 KB Output is correct
73 Correct 2873 ms 261824 KB Output is correct
74 Correct 1463 ms 263412 KB Output is correct
75 Correct 1297 ms 263408 KB Output is correct
76 Execution timed out 3102 ms 264304 KB Time limit exceeded
77 Halted 0 ms 0 KB -