2 条题解

  • 0
    @ 2025-11-13 20:22:46
    using namespace std;
    int main(){
    	int t;
    	cin>>t;
    	while(t--){
    		int n,m;
    		cin>>n>>m;
    		int a[205][205];
    		for(int i=0;i<n;i++){
    			for(int j=0;j<m;j++){
    				cin>>a[i][j];
    			}
    		}
    		long long d1[500]={0};
    		long long d2[500]={0};
    		for(int i=0;i<n;i++){
    			for(int j=0;j<m;j++){
    				d1[i-j+200]+=a[i][j];
    				d2[i+j]+=a[i][j];	
    			}
    		}
    			long long ans=0;
    			for (int i=0;i<n;i++) {
    				for (int j=0;j<m;j++){
    					long long s=d1[i-j+200]+d2[i+j]-a[i][j];
    					if (s>ans)ans=s;
    				}
    			}
    			cout<<ans<<endl;	
    }return 0;
    	
    }
    
    • 0
      @ 2025-11-8 19:45:46
      #include<bits/stdc++.h>
      using namespace std;
      #define int long long
      void solve() {
          int n,m; cin >> n >> m;
          int a[n+1][m+1] = {0};
          // sa存“差对角线”和,sb存“和对角线”和;
          // 数组大小1000足够(因n,m最大200)
          int sa[1000] = {0}, sb[1000] = {0};
          int ans = 0;
          for(int i = 1; i <= n; i++){
              for(int j = 1; j <= m; j++){
                  cin >> a[i][j];
                  // 将a[i][j]累加到其“差对角线”的和中
                  sa[i - j + n + m] += a[i][j];  
                  // 将a[i][j]累加到其“和对角线”的和中
                  sb[i + j] += a[i][j];        
              }
          }
          for(int i = 1; i <= n; i++){
              for(int j = 1; j <= m; j++){
                  // 计算(i,j)作为主教位置的攻击和:两条对角线和之和 - 自身
                  ans = max(ans, sa[i - j + n + m] + sb[i + j] - a[i][j]);
              }
          }
          cout << ans << '\n';
      }
      signed main() {
          ios::sync_with_stdio(false);
          cin.tie(nullptr), cout.tie(nullptr);
          int T = 1;
          cin >> T;
          while (T--) solve();
          return 0;
      }
      
      • 1

      信息

      ID
      1191
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      (无)
      递交数
      82
      已通过
      27
      上传者