long long 60分 __int128 0分 求助
查看原帖
long long 60分 __int128 0分 求助
220824
yyz1005楼主2022/7/12 11:29

long long 代码(60pts)

#include<iostream>
#include<cstdio>
using namespace std;
long long n,m,a[100];
long long dp[100][100];
int main(){
    long long cnt = 0;
    cin >> n >> m;
    for(long long i = 1; i <= n; i++){
        for(long long j = 1; j <= m; j++) cin >> a[j];
        for(long long s = m; s >= 1; s--){
            for(long long e = s; e <= m; e++){
                dp[s][e] = 1000000000000010;
                if(s==e) dp[s][e] = a[s];
                else {
                    dp[s][e] = max(a[s]+dp[s+1][e]*2,a[e]+dp[s][e-1]*2);
                }
            }
        }
        cnt+=dp[1][m]*2;
    }
    cout << cnt;
    return 0;
}

__int128 0pts

全 WA 下载了样例1,但是输出是一样的

不知道是哪里错了

是输出的问题吗

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
__int128 n,m,a[100];
__int128 dp[100][100];
__int128 in128(){
	__int128 x = 0;
	int f = 1;
	char ch;
	ch = getchar();
	if(ch=='-') f = -1;
	else x = ch-'0';
	ch = getchar();
	while('0'<=ch&&ch<='9'){
		x = x*10+ch-'0';
		ch = getchar();
	}
	return x;
}
void put128(__int128 x){
	if(x<0){
		x = -x;
		cout << "-";
	}
	if(x>9) put128(x/10);
	putchar(x%10+'0');
}
int main(){
	__int128 cnt = 0;
	n = in128(),m = in128();
	for(__int128 i = 1; i <= n; i++){
		for(__int128 j = 1; j <= m; j++) a[j] = in128();
		for(__int128 s = m; s >= 1; s--){
			for(__int128 e = s; e <= m; e++){
				dp[s][e] = 1000000000000010;
				if(s==e) dp[s][e] = a[s];
				else {
					dp[s][e] = max(a[s]+dp[s+1][e]*2,a[e]+dp[s][e-1]*2);
				}
			}
		}
		cnt+=dp[1][m]*2;
	}
	put128(cnt);
	return 0;
}
2022/7/12 11:29
加载中...