Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 5e2;
- using lli = long long;
- vector <lli> a, b, c, d;
- int main(){
- int n;
- scanf("%d", &n);
- int aa = 1, bb = 1;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=n;j++){
- lli input;
- scanf("%lld", &input);
- int x = i % 2;
- int y = j % 2;
- if(x == 1 and y == 1) a.push_back(input);
- else if(x == 1 and y == 0) b.push_back(input);
- else if(x == 0 and y == 1) c.push_back(input);
- else if(x == 0 and y == 0) d.push_back(input);
- }
- }
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- sort(c.begin(), c.end());
- sort(d.begin(), d.end());
- lli sum = 0;
- int sz = a.size();
- for(int i=0;i<sz;i++){
- sum += (lli) a[i] * b[i] * c[i] * d[i];
- }
- printf("%lld", sum);
- return 0;
- }
- /*
- greedy
- a b a b a b ...
- c d c d c d ...
- a b a b a b ...
- c d c d c d ...
- . . . . . .
- . . . . . .
- . . . . . .
- ภายใน a b c d สามารถสลับตำแหน่งกันได้ทั้งหมด
- ดังนั้นจึง sort เพื่อนำเลขมากมาคูณกัน
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement