/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 516.0 KiB
#2 Wrong Answer 2ms 540.0 KiB
#3 Wrong Answer 20ms 584.0 KiB
#4 Wrong Answer 20ms 616.0 KiB
#5 Accepted 13ms 1.434 MiB
#6 Accepted 39ms 4.27 MiB
#7 Accepted 40ms 4.5 MiB
#8 Accepted 40ms 4.516 MiB
#9 Accepted 40ms 4.273 MiB
#10 Accepted 40ms 4.492 MiB
#11 Accepted 38ms 4.504 MiB
#12 Accepted 37ms 4.484 MiB
#13 Wrong Answer 13ms 624.0 KiB
#14 Wrong Answer 15ms 540.0 KiB
#15 Accepted 1ms 540.0 KiB
#16 Wrong Answer 45ms 1.777 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 505 ;
int Arr[sz][sz] , n , m , val;
int dx[] = {-1 , 0 , 0 , 1} ;
int dy[] = {0 , 1 , -1 , 0} ;
int heart(int x , int y){
   int cur = INT_MAX ;
  for(int i = 0 ; i < 4 ; i++){
    int cur_i = dx[i] + x ;
    int cur_j = dy[i] + y ;
    if(cur_i >= 0 && cur_i < n && cur_j >= 0 && cur_j < m){
        cur = min(cur , Arr[cur_i][cur_j] + Arr[x][y]) ;
    }
  }
  return cur ;
}
void solve()
{
    cin >> n >> m ;
   vector < int > v ;
   vector < PII > V ;
   for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
        cin >> val ;
        v.pb(val) ;
    }
   }
   sort_a(v) ;
   int st = 0 , en = v.size() - 1 , pos_i = 0 , pos_j = 0;
   while(st < en){
    V.pb({v[st] , v[en]}) ;
    st++ ;
    en-- ;
   }
   if(st == en) V.pb({v[st] , v[en]}) ;
//   for(auto it : V){
//    cout << it.F << " " << it.S << endl ;
//   }

   for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
        int cur = i + j ;
        if(cur & 1) Arr[i][j] = V[pos_j++].S ;
        else Arr[i][j] = V[pos_i++].F ;
    }
   }
   int Ans = INT_MAX ;
   for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
        Ans = min(Ans , heart(i , j)) ;
    }
   }
   cout << Ans << "\n" ;
}
int main()
{
     __Heart__
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1065 Matrix Sum
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-12 23:08:04
Judged At
2024-07-12 23:08:04
Judged By
Score
70
Total Time
45ms
Peak Memory
4.516 MiB