1 条题解
-
1
参考答案:
#include <bits/stdc++.h>//朴素版 using namespace std; #define ls u << 1 #define rs u << 1 | 1 #define LL long long #define int long long #define PII pair <int, int> #define fi first #define se second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define i128 __int128 #define pcnt(x) __builtin_popcount(x) #define mem(a,goal) memset(a, (goal), sizeof(a)) #define rep(x,start,end) for(int x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); ((start) < (end) ? x ++ : x --)) #define aLL(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const int INF = 998244353; const int P = 1e9 + 7; const int N = 2e5 + 5; int a[1010][1010]; void solve() { int n; cin >> n; for(int i = 1; i <= n; ++ i) { for(int j = 1; j <= n; ++ j) { cin >> a[i][j]; } } int sum = 0; for(int i = 1; i <= n; ++ i) { int t = 0; for(int j = 1; j <= i; ++ j) { if(a[j][n - i + j] < 0) t = min(t, a[j][n - i + j]); } sum += abs(t); } for(int i = 1 ; i < n; ++ i) { int t = 0; for(int j = 1; j <= i; ++ j) { if(a[n - i + j][j] < 0) t = min(t, a[n - i + j][j]); } sum += abs(t); } cout << sum << '\n'; } signed main() { int t; cin >> t; while(t --) solve(); return 0; }
/** * author: 小飞侠 * created: 2024.10.28 19:10:38 */ #include <bits/stdc++.h>//精简版 using namespace std; #define ls u << 1 #define rs u << 1 | 1 #define LL long long #define int long long #define PII pair <int, int> #define fi first #define se second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define i128 __int128 #define pcnt(x) __builtin_popcount(x) #define mem(a,goal) memset(a, (goal), sizeof(a)) #define rep(x,start,end) for(int x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); ((start) < (end) ? x ++ : x --)) #define aLL(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const int INF = 998244353; const int P = 1e9 + 7; const int N = 1e3 + 5; int c[N]; int a[N][N]; void solve() { int n; cin >> n; for(int i = 1; i <= n; ++ i) { for(int j = 1; j <= n; ++ j) { cin >> a[i][j]; } } for(int i = 1; i <= n; ++ i) { for(int j = 1; j <= n; ++ j) { c[i - j + n] = max(c[i - j + n], - a[i][j]); } } int ans = 0; for(int i = 1; i <= 2 * n; ++ i) { ans += c[i]; c[i] = 0; } cout << ans << endl; } signed main() { int t; cin >> t; while(t --) solve(); return 0; }
- 1
信息
- ID
- 5434
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 6
- 已通过
- 3
- 上传者