답안 #629473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629473 2022-08-14T14:11:01 Z jh05013 메기 농장 (IOI22_fish) C++17
14 / 100
1000 ms 2097152 KB
#include <bits/stdc++.h>
using namespace std;
void OJize(){cin.tie(NULL);ios_base::sync_with_stdio(false);}

typedef long long ll;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define sz(X) (int)((X).size())
#define entire(X) X.begin(),X.end()
template <class T1, class T2>ostream&operator<<(ostream &os,pair<T1,T2>const&x){os<<'('<<x.first<<", "<<x.second<<')';return os;}
template <class Ch, class Tr, class Container>basic_ostream<Ch,Tr>&operator<<(basic_ostream<Ch,Tr>&os,Container const&x){os<<"[ ";for(auto&y:x)os<<y<<" ";return os<<"]";}

ll max_weights(int L, int n,
vector<int> X, vector<int> Y, vector<int> W){
	vector<vector<ll>> grid(L, vector<ll>(L+1));
	for(int i=0; i<n; i++) grid[X[i]][Y[i]] = (ll)W[i];

	vector<ll> dinc(L+1), ddec(L+1);
	// column _,
	// last column height j,
	// next will increase/decrease
	for(int i=1; i<L; i++){
		vector<ll> ndinc(L+1), nddec(L+1);
		ndinc[0] = nddec[0] = ddec[0];
		ndinc[L] = nddec[L] = max(ddec[0], dinc[L]);
		for(int y=0; y<=L; y++){
			if(!(y == L || y == 0 || grid[i][y])) continue;
			for(int y0=0; y0<y; y0++){ // inc
				if(!(y0 == L || y0 == 0 || grid[i-1][y0])) continue;
				// take [i-1][y0 to y-1]
				ll val = dinc[y0];
				for(int z=y0; z<y; z++) val+= grid[i-1][z];
				ndinc[y] = max(ndinc[y], val);
				if(y == L) nddec[y] = max(nddec[y], val);
			}
			for(int y0=y+1; y0<=L; y0++){ // dec
				if(!(y0 == L || y0 == 0 || grid[i-1][y0])) continue;
				// take [i][y to y0-1]
				ll val = ddec[y0];
				for(int z=y; z<y0; z++) val+= grid[i][z];
				nddec[y] = max(nddec[y], val);
			}
		}
		dinc = ndinc, ddec = nddec;
	}

	return max(
		*max_element(entire(dinc)),
		*max_element(entire(ddec))
	);
}

#ifdef jh
int main(){OJize();
	int n; cin>>n;
	vector<int> X, Y, W;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++){
		int x; cin>>x;
		if(x){
			X.push_back(j);
			Y.push_back(n-1-i);
			W.push_back(x);
		}
	}
	cout << max_weights(n, sz(X), X, Y, W);
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Runtime error 739 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 759 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 703 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 952 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 634 ms 2864 KB Output is correct
18 Correct 713 ms 2836 KB Output is correct
19 Correct 324 ms 2772 KB Output is correct
20 Correct 247 ms 2832 KB Output is correct
21 Correct 244 ms 2812 KB Output is correct
22 Execution timed out 1087 ms 4556 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 952 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 634 ms 2864 KB Output is correct
18 Correct 713 ms 2836 KB Output is correct
19 Correct 324 ms 2772 KB Output is correct
20 Correct 247 ms 2832 KB Output is correct
21 Correct 244 ms 2812 KB Output is correct
22 Execution timed out 1087 ms 4556 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 703 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 739 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -