Submission #90501

# Submission time Handle Problem Language Result Execution time Memory
90501 2018-12-22T01:07:41 Z psmao Maja (COCI18_maja) C++14
0 / 110
3 ms 724 KB
#include <bits/stdc++.h>
using namespace std;

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 105;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {-1, 1, 0, 0};

int n, m, A[maxn][maxn], P[maxn][maxn], a, b, K;
ll V[2][maxn][maxn], Ans;
vector<pii> candi;

int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	sf("%d%d%d%d%d",&n,&m,&a,&b,&K);
	fo(i,1,n) fo(j,1,m) sf("%d",&A[i][j]);
	fo(i,1,n) fo(j,1,m) fo(k,0,3) P[i][j] = max(P[i][j], A[i][j] + A[i+dx[k]][j+dy[k]]);
	int lim = min(K/2,n*m-1);
	fo(len,1,lim)
	{
		int now = len&1, las = now^1;
		for(auto q : candi)
		{
			int i = q.fi, j = q.se; 
			fo(k,0,3) 
			{
				int nx = i + dx[k], ny = j + dy[k];
				if(nx < 1 || ny < 1 || nx > n || ny > m) continue;
				V[now][i][j] = max(V[now][i][j], V[las][nx][ny] + A[i][j]);
			}
		}	
	}
	Ans = -INF;
	fo(i,1,n) fo(j,1,m) 
	{
		// int k = K/2-d[i][j];
		// if(k < 0) continue;
		Ans = max(Ans, 1ll*(K/2-lim)*P[i][j] + V[lim&1][i][j]*2 - A[i][j]);
		// cout << i << ' '<< j << ' ' << ' ' << V[lim&1][i][j]*2 << ' ' << K/2-lim << ' '<< P[i][j] << ' ' << 1ll*(K/2-lim)*P[i][j] + V[lim&1][i][j]*2 - A[i][j] << endl;
	}
	cout << Ans << endl;
	return 0;
}

Compilation message

maja.cpp: In function 'int main()':
maja.cpp:47:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d%d%d%d",&n,&m,&a,&b,&K);
    ^
maja.cpp:48:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fo(i,1,n) fo(j,1,m) sf("%d",&A[i][j]);
                        ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -