Submission #261351

# Submission time Handle Problem Language Result Execution time Memory
261351 2020-08-11T16:26:49 Z Saboon Treatment Project (JOI20_treatment) C++14
5 / 100
655 ms 172008 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int maxl = 20;

int T[maxn], fen[maxn], L[maxn], R[maxn], C[maxn], p[maxn];
ll dp[maxn];
vector<pair<int,ll>> g[maxn*maxl];
int newint;

void dijkstra(int v){
	memset(dp, -1, sizeof dp);
	set<pair<ll,int>> s;
	dp[v] = 0;
	s.insert({dp[v], v});
	while (!s.empty()){
		v = (*s.begin()).second;
		s.erase(s.begin());
		for (auto [u, w] : g[v]){
			if (dp[u] == -1 or dp[u] > dp[v] + w){
				s.erase({dp[u],u});
				dp[u] = dp[v] + w;
				s.insert({dp[u],u});
			}
		}
	}
}

void add(int idx, int val){
	for (; idx < maxn; idx += idx & -idx){
		int then = newint ++;
		if (fen[idx] != 0)
			g[then].push_back({fen[idx],0});
		fen[idx] = then;
		g[then].push_back({val,C[val]});
	}
}

void get(int idx, int val){
	for (; idx; idx -= idx & -idx)
		if (fen[idx] != 0)
			g[val].push_back({fen[idx],0});
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> T[i] >> L[i] >> R[i] >> C[i];
	for (int i = 1; i <= m; i++)
		p[i] = i;
	sort(p+1, p+m+1, [](int a, int b){ return T[a] < T[b];});
	newint = m+3;
	for (int iit = 1; iit <= m; iit++){
		int i = p[iit];
		if (L[i] == 1)
			g[0].push_back({i,C[i]});
		if (R[i] == n)
			g[i].push_back({m+1, 0});
	}
	vector<pair<int,int>> event;
	for (int iit = 1; iit <= m; iit++){
		int i = p[iit];
		event.push_back({L[i]-T[i], -iit});
		event.push_back({R[i]-T[i]+1, +iit});
	}
	sort(event.begin(), event.end());
	for (auto [chert,iit] : event){
		if (iit < 0)
			add(-iit, p[-iit]);
		else
			get(iit, p[iit]);
	}
	event.clear();
	memset(fen, 0, sizeof fen);
	reverse(p+1, p+m+1);
	for (int iit = 1; iit <= m; iit++){
		int i = p[iit];
		event.push_back({L[i]+T[i], -iit});
		event.push_back({R[i]+T[i]+1, +iit});
	}
	sort(event.begin(), event.end());
	for (auto [chert,iit] : event){
		if (iit < 0)
			add(-iit, p[-iit]);
		else
			get(iit, p[iit]);
	}
	dijkstra(0);
	cout << dp[m+1] << endl;
}

Compilation message

treatment.cpp: In function 'void dijkstra(int)':
treatment.cpp:20:13: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
   for (auto [u, w] : g[v]){
             ^
treatment.cpp: In function 'int main()':
treatment.cpp:70:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
  for (auto [chert,iit] : event){
            ^
treatment.cpp:70:22: warning: unused variable 'chert' [-Wunused-variable]
  for (auto [chert,iit] : event){
                      ^
treatment.cpp:85:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
  for (auto [chert,iit] : event){
            ^
treatment.cpp:85:22: warning: unused variable 'chert' [-Wunused-variable]
  for (auto [chert,iit] : event){
                      ^
# Verdict Execution time Memory Grader output
1 Incorrect 655 ms 172008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 48504 KB Output is correct
2 Correct 37 ms 48512 KB Output is correct
3 Correct 36 ms 48504 KB Output is correct
4 Correct 61 ms 48504 KB Output is correct
5 Correct 34 ms 48504 KB Output is correct
6 Correct 57 ms 48488 KB Output is correct
7 Correct 34 ms 48536 KB Output is correct
8 Correct 34 ms 48504 KB Output is correct
9 Correct 40 ms 48504 KB Output is correct
10 Correct 37 ms 48504 KB Output is correct
11 Correct 37 ms 48508 KB Output is correct
12 Correct 34 ms 48504 KB Output is correct
13 Correct 38 ms 48512 KB Output is correct
14 Correct 36 ms 48504 KB Output is correct
15 Correct 51 ms 48632 KB Output is correct
16 Correct 38 ms 48504 KB Output is correct
17 Correct 37 ms 48504 KB Output is correct
18 Correct 35 ms 48504 KB Output is correct
19 Correct 38 ms 48504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 48504 KB Output is correct
2 Correct 37 ms 48512 KB Output is correct
3 Correct 36 ms 48504 KB Output is correct
4 Correct 61 ms 48504 KB Output is correct
5 Correct 34 ms 48504 KB Output is correct
6 Correct 57 ms 48488 KB Output is correct
7 Correct 34 ms 48536 KB Output is correct
8 Correct 34 ms 48504 KB Output is correct
9 Correct 40 ms 48504 KB Output is correct
10 Correct 37 ms 48504 KB Output is correct
11 Correct 37 ms 48508 KB Output is correct
12 Correct 34 ms 48504 KB Output is correct
13 Correct 38 ms 48512 KB Output is correct
14 Correct 36 ms 48504 KB Output is correct
15 Correct 51 ms 48632 KB Output is correct
16 Correct 38 ms 48504 KB Output is correct
17 Correct 37 ms 48504 KB Output is correct
18 Correct 35 ms 48504 KB Output is correct
19 Correct 38 ms 48504 KB Output is correct
20 Correct 73 ms 55416 KB Output is correct
21 Correct 79 ms 55416 KB Output is correct
22 Incorrect 64 ms 54780 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 655 ms 172008 KB Output isn't correct
2 Halted 0 ms 0 KB -