/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 10ms 588.0 KiB
#3 Accepted 429ms 636.0 KiB
#4 Accepted 452ms 644.0 KiB
#5 Accepted 374ms 2.945 MiB
#6 Accepted 1830ms 14.301 MiB
#7 Accepted 1538ms 14.309 MiB
#8 Accepted 1388ms 14.426 MiB
#9 Accepted 1442ms 14.352 MiB
#10 Accepted 1433ms 14.41 MiB
#11 Accepted 1983ms 14.32 MiB
#12 Wrong Answer 1965ms 14.344 MiB
#13 Accepted 244ms 648.0 KiB
#14 Accepted 296ms 644.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=1e7+1,MOD=1000000007;
typedef long long ll;
#define double long double
#define debug(x) cout<<x<<endl
int a[800][800];
void clr(int n){
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)a[i][j]=1e5;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
      vector<int>st;
       for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int b;
            cin>>b;
            st.push_back(b);
       }
   }
   sort(st.begin(),st.end());
       int l=-2e4,r=2e4;
       int res=-1e5;
       while(l<=r){
        int mid=l+(r-l)/2;
        int ok=1;
        multiset<int>st1;
        for(auto it:st)st1.insert(it);
        clr(n);
        for(int i=1;i<=n&&ok;i++){
            for(int j=1;j<=n&&ok;j++){
                if(i==1 && j==1){
                    auto it=st1.begin();
                    a[i][j]=*it;
                    st1.erase(st1.find(a[i][j]));
                }
                else{
                    int x=min(a[i-1][j],a[i][j-1]);
                    int lagba=mid-x;
                    auto it=st1.lower_bound(lagba);
                    if(it==st1.end()){
                        ok=0;
                        break;
                    }
                    a[i][j]=*it;
                    st1.erase(st1.find(a[i][j]));
                }
                
            }
        }
        int ok1=1;
        clr(n);
        st1.clear();
        for(auto it:st)st1.insert(it);
         for(int i=1;i<=n&&ok1;i++){
            for(int j=1;j<=n&&ok1;j++){
                if(i==1 && j==1){
                    auto it=st1.rbegin();
                    a[i][j]=*it;
                    st1.erase(st1.find(a[i][j]));
                }
                else{
                    int x=min(a[i-1][j],a[i][j-1]);
                    int lagba=mid-x;
                    auto it=st1.lower_bound(lagba);
                    if(it==st1.end()){
                        ok1=0;
                        break;
                    }
                    a[i][j]=*it;
                    st1.erase(st1.find(a[i][j]));
                }
                
            }
        }
        if(ok || ok1){
            res=mid;
            l=mid+1;
        }
        else r=mid-1;

       }
       cout<<res<<"\n";
    }


    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1065 Matrix Sum
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-30 17:23:00
Judged At
2024-05-30 17:23:00
Judged By
Score
95
Total Time
1983ms
Peak Memory
14.426 MiB