답안 #587571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587571 2022-07-02T05:46:48 Z Red_Inside Team Contest (JOI22_team) C++17
37 / 100
2000 ms 6216 KB
//
#include <bits/stdc++.h>

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

using namespace std;
const int maxn=3e5+10,LOG=17, mod=1e9+7;
int block = 320, timer = 0;
const ld EPS = 1e-18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define bt(i) (1 << (i))
#define int ll
const int inf=2e18;
#define y1 yy
#define prev pre
#define pii pair <int, int>

int n, a[maxn], b[maxn], c[maxn], ind[maxn], pref[maxn], ind2[maxn], ok[maxn];

bool cmp(int i, int j)
{
	if(a[i] == a[j])
	{
		if(b[i] == b[j]) return c[i] < c[j];
		else return b[i] < b[j];
	}
	else return a[i] < a[j];
}

void add(int I)
{
	int A = a[I];
	int B = b[I];
	int C = c[I];
	int pos;
	forn(1, i, n)
	{
		if(ind2[i] == I)
		{
			pos = i;
		}
	}
	ok[pos] = 1;
	forn(pos, i, n)
	{
		pref[i] = max(pref[i], C);
	}
}

int check(int A, int B, int C)
{
	int ret = -inf;
	int last = 0;
	forn(1, i, n)
	{
		if(!ok[i]) continue;
		if(b[ind2[last]] != b[ind2[i]])
		{
			last = i;
		}
		if(last != 0 && pref[last - 1] > max(C, c[ind2[i]]) && b[ind2[i]] > B)
		{
//			cout << A << " " <<  ind2[i] << " " << pref[last - 1] << " " << b[ind2[i]] << endl;
			ret = max(ret, pref[last - 1] + A + b[ind2[i]]);
		}
	}
//	o
	return ret;
}

bool cmp2(int i, int j)
{
	if(b[i] == b[j])
	{
		return c[i] < c[j];
	}
	return b[i] < b[j];
}

main()
{
	IOS
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i] >> b[i] >> c[i];
		ind[i] = i;
		ind2[i] = i;
	}
	sort(ind2 + 1, ind2 + 1 + n, cmp2);
	forn(1, i, 4000) pref[i] = -inf;
	sort(ind + 1, ind + 1 + n, cmp);
	int ans = -inf;
	forn(1, i, n)
	{
		int j = i;
		while(a[ind[j+1]] == a[ind[i]])
		{
//			if(ind[j] == 10) cout << "jfla;ksdjf;alsdjf;akls;a\n";
			ans = max(ans, check(a[ind[j]], b[ind[j]], c[ind[j]]));
			++j;
		}
//		if(ind[j] == 10) cout << "dja;fklsjd;fas;g\n";
		ans = max(ans, check(a[ind[j]], b[ind[j]], c[ind[j]]));
		forn(i, k, j)
		{
			add(ind[k]);
		}
		i = j;
	}
	if(ans < 0) cout << -1;
	else
		cout << ans;
}

Compilation message

team.cpp: In function 'void add(long long int)':
team.cpp:46:6: warning: unused variable 'A' [-Wunused-variable]
   46 |  int A = a[I];
      |      ^
team.cpp:47:6: warning: unused variable 'B' [-Wunused-variable]
   47 |  int B = b[I];
      |      ^
team.cpp: At global scope:
team.cpp:94:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   94 | main()
      | ^~~~
team.cpp: In function 'void add(long long int)':
team.cpp:49:6: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |  int pos;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 50 ms 468 KB Output is correct
27 Correct 59 ms 568 KB Output is correct
28 Correct 63 ms 576 KB Output is correct
29 Correct 61 ms 588 KB Output is correct
30 Correct 28 ms 532 KB Output is correct
31 Correct 63 ms 576 KB Output is correct
32 Correct 50 ms 560 KB Output is correct
33 Correct 29 ms 568 KB Output is correct
34 Correct 34 ms 596 KB Output is correct
35 Correct 3 ms 440 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 49 ms 576 KB Output is correct
38 Correct 45 ms 572 KB Output is correct
39 Correct 16 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2072 ms 6216 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2072 ms 6216 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2072 ms 6216 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2072 ms 6216 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 50 ms 468 KB Output is correct
27 Correct 59 ms 568 KB Output is correct
28 Correct 63 ms 576 KB Output is correct
29 Correct 61 ms 588 KB Output is correct
30 Correct 28 ms 532 KB Output is correct
31 Correct 63 ms 576 KB Output is correct
32 Correct 50 ms 560 KB Output is correct
33 Correct 29 ms 568 KB Output is correct
34 Correct 34 ms 596 KB Output is correct
35 Correct 3 ms 440 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 49 ms 576 KB Output is correct
38 Correct 45 ms 572 KB Output is correct
39 Correct 16 ms 512 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Execution timed out 2072 ms 6216 KB Time limit exceeded
51 Halted 0 ms 0 KB -