CSES - Datatähti 2024 qualification mirror - Results
Submission details
Task:Uolevin kalansaalis
Sender:nokka7
Submission time:2023-10-31 03:22:53 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

output/ccRsqIJU.o: in function `tulosta_verkko(int (*) [500])':
code.cpp:(.text+0x23): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in output/ccRsqIJU.o
code.cpp:(.text+0x45): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in output/ccRsqIJU.o
code.cpp:(.text+0x73): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in output/ccRsqIJU.o
code.cpp:(.text+0x97): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in output/ccRsqIJU.o
output/ccRsqIJU.o: in function `tulosta_dp(int (*) [500][500])':
code.cpp:(.text+0xe3): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in output/ccRsqIJU.o
code.cpp:(.text+0xea): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in output/ccRsqIJU.o
code.cpp:(.text+0x136): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defin...

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, k, a, b;
char c;
int ve[500][500]={0};
int yk[500][500]={0};
int ak[500][500]={0};
int dp[1000][1000][1000];

void tulosta_verkko(int verkko[][500] ) {
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cout << verkko[i][j] << " ";
		}
		cout << "\n";
	}
	cout << "\n";
}
void tulosta_dp(int verkko[][500][500] ) {
	for (int k=0; k<min(n,m); k++) {
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cout << verkko[i][j][k] << " ";
		}
		cout << "\n";
	}
	cout << "\n";
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> k;
	int tot=0;
	for (int i=0; i<k; i++) {
		cin >> a >> b >> c;
		if (c=='H') {
			tot++;
		       	ve[a-1][b-1]=1;
		}
		else {
			tot-=10;
		       	ve[a-1][b-1]=-10;
		}
	}
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			int ylaraja=i+1;
			int alaraja=n-i;
			int vasenraja,oikearaja;
			if (i%2==0) {
				vasenraja=j*2+1;
				oikearaja=(m-j)*2;
			} else {
				vasenraja=(j+1)*2;
				oikearaja=(m-j)*2-1;
			}
			yk[i][j]=min(ylaraja,min(vasenraja,oikearaja));
			ak[i][j]=min(alaraja,min(vasenraja,oikearaja));
		}
        }
	int mini=0;
	for (int i=0; i<n; i++) { // yksi pikku optimointi olisi lisata kaikkiin ve[i][j]
		for (int j=0; j<m; j++) {
			dp[i][j][0]=ve[i][j];
			mini=min(mini,dp[i][j][0]);
			if (yk[i][j]>1) {
				if (i%2==0) dp[i][j][1]=ve[i][j]+ve[i-1][j-1]+ve[i-1][j];
				else dp[i][j][1]=ve[i][j]+ve[i-1][j]+ve[i-1][j+1];
			}
			mini=min(mini,dp[i][j][1]);
			for (int k=2; k<yk[i][j]; k++) {
				if (i%2==0) {
					dp[i][j][k]=ve[i][j]+dp[i-1][j-1][k-1]+dp[i-1][j][k-1]-dp[i-2][j][k-2];
				} else {
					dp[i][j][k]=ve[i][j]+dp[i-1][j][k-1]+dp[i-1][j+1][k-1]-dp[i-2][j][k-2];
				}
				mini=min(mini,dp[i][j][k]);
			}
		}
        }
	for (int i=n-1; i>=0; i--) { // yksi pikku optimointi olisi lisata kaikkiin ve[i][j]
		for (int j=m-1; j>=0; j--) {
			dp[i][j][0]=ve[i][j];
			mini=min(mini,dp[i][j][0]);
			if (ak[i][j]>1) {
				if (i%2==0) dp[i][j][1]=ve[i][j]+ve[i+1][j-1]+ve[i+1][j];
				else dp[i][j][1]=ve[i][j]+ve[i+1][j]+ve[i+1][j+1];
			}
			mini=min(mini,dp[i][j][1]);
			for (int k=2; k<ak[i][j]; k++) {
				if (i%2==0) {
					dp[i][j][k]=ve[i][j]+dp[i+1][j-1][k-1]+dp[i+1][j][k-1]-dp[i+2][j][k-2];
				} else {
					dp[i][j][k]=ve[i][j]+dp[i+1][j][k-1]+dp[i+1][j+1][k-1]-dp[i+2][j][k-2];
				}
				mini=min(mini,dp[i][j][k]);
			}
		}
        }
	cout << tot-mini << "\n";
	//tulosta_dp(dp);
	//tulosta_verkko(yk);
	//tulosta_verkko(ak);
}