Submission #832199

# Submission time Handle Problem Language Result Execution time Memory
832199 2023-08-21T06:36:28 Z ymm Catfish Farm (IOI22_fish) C++17
9 / 100
136 ms 33484 KB
#include "fish.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= l; --x)
typedef long long ll;
using namespace std;

const int N = 100'032;

struct fish {
	int pos = 0;
	int weight = 0;
	ll dpu = 0;
	ll dpd = 0;

	fish() {}
	fish(int x) : pos(x) {}
	fish(int x, int w) : pos(x), weight(w) {}
	bool operator<(const fish &f) const { return pos < f.pos; }
};

vector<fish> a[N];

fish &nxt_up(vector<fish> &vec, fish &cur) { return *upper_bound(vec.begin(), vec.end(), cur); }
fish &nxt_do(vector<fish> &vec, fish &cur) { return *--lower_bound(vec.begin(), vec.end(), cur); }

long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
	Loop (i,0,m)
		a[X[i]].push_back(fish(Y[i], W[i]));
	Loop (i,0,n) {
		a[i].push_back(fish(-1));
		a[i].push_back(fish(n));
		sort(a[i].begin(), a[i].end());
	}
	LoopR (i,0,n) {
		a[i].front().dpd = (i+1 < n? a[i+1].front().dpu: 0);
		Loop (j,1,a[i].size()) {
			a[i][j].dpd = nxt_do(a[i], a[i][j]).dpd;
			if (i+1 < n)
				a[i][j].dpd = max(a[i][j].dpd, nxt_do(a[i+1], a[i][j]).dpd);
			a[i][j].dpd += a[i][j].weight;
		}
		if (i == n-1)
			continue;
		a[i].back().dpu = (i+2 < n? a[i+2].back().dpd: 0);
		LoopR (j,0,a[i].size()-1) {
			a[i][j].dpu = nxt_up(a[i], a[i][j]).dpu;
			if (i+1 < n)
				a[i][j].dpu = max(a[i][j].dpu, nxt_up(a[i+1], a[i][j]).dpu);
			a[i][j].dpu += a[i][j].weight;
		}
	}
	return max(a[0].front().dpu, a[1].back().dpd);
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<fish>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
fish.cpp:38:3: note: in expansion of macro 'Loop'
   38 |   Loop (j,1,a[i].size()) {
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 13500 KB Output is correct
2 Correct 63 ms 15300 KB Output is correct
3 Correct 11 ms 8792 KB Output is correct
4 Correct 10 ms 8916 KB Output is correct
5 Correct 136 ms 29304 KB Output is correct
6 Correct 120 ms 33484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 84 ms 18728 KB Output is correct
3 Correct 104 ms 21728 KB Output is correct
4 Correct 46 ms 13408 KB Output is correct
5 Correct 53 ms 15304 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 11 ms 8796 KB Output is correct
11 Correct 11 ms 8880 KB Output is correct
12 Correct 43 ms 13436 KB Output is correct
13 Correct 52 ms 15312 KB Output is correct
14 Correct 44 ms 13492 KB Output is correct
15 Correct 51 ms 14640 KB Output is correct
16 Correct 44 ms 13408 KB Output is correct
17 Correct 48 ms 14588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8788 KB Output is correct
2 Correct 10 ms 8916 KB Output is correct
3 Incorrect 29 ms 13204 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Incorrect 2 ms 2660 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Incorrect 2 ms 2660 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Incorrect 2 ms 2660 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8788 KB Output is correct
2 Correct 10 ms 8916 KB Output is correct
3 Incorrect 29 ms 13204 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 13500 KB Output is correct
2 Correct 63 ms 15300 KB Output is correct
3 Correct 11 ms 8792 KB Output is correct
4 Correct 10 ms 8916 KB Output is correct
5 Correct 136 ms 29304 KB Output is correct
6 Correct 120 ms 33484 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 84 ms 18728 KB Output is correct
9 Correct 104 ms 21728 KB Output is correct
10 Correct 46 ms 13408 KB Output is correct
11 Correct 53 ms 15304 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 11 ms 8796 KB Output is correct
17 Correct 11 ms 8880 KB Output is correct
18 Correct 43 ms 13436 KB Output is correct
19 Correct 52 ms 15312 KB Output is correct
20 Correct 44 ms 13492 KB Output is correct
21 Correct 51 ms 14640 KB Output is correct
22 Correct 44 ms 13408 KB Output is correct
23 Correct 48 ms 14588 KB Output is correct
24 Correct 11 ms 8788 KB Output is correct
25 Correct 10 ms 8916 KB Output is correct
26 Incorrect 29 ms 13204 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412'
27 Halted 0 ms 0 KB -