Submission #7067213


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    ll H,W; cin >> H >> W;
    bool five=false;
    int ma=0;
    vector<int> loc5;
    int a[H*W];
    rep(i,H*W){
        cin >> a[i];
        if(a[i]==5){
            five=true;
            loc5.push_back(i);
        }
        chmax(ma,a[i]);
    }
    if(ma==0)cout << "Yes" << ' ' << 0;
    else if(five){
        if(H!=1 && W!=1){ 
        cout << "Yes" << ' ';
            if(ma<=5)cout << 1;
            if(ma==6)cout << 2;
            if(ma==7)cout << 2;
            if(ma==8)cout << 3;
            if(ma==9)cout << 4;
        }
        else{
            int mini=100;
            for(auto x:loc5){
                int ml=0;
                int mr=0;
                rep(i,x){
                    chmax(ml,a[i]);
                }
                for(int i=x+1;i<H*W;i++){
                    chmax(mr,a[i]);
                }
                if(ml<=5)ml=0;
                if(ml==6)ml=1;
                if(ml==7)ml=1;
                if(ml==8)ml=2;
                if(ml==9)ml=3;
                if(mr<=5)mr=0;
                if(mr==6)mr=1;
                if(mr==7)mr=1;
                if(mr==8)mr=2;
                if(mr==9)mr=3;
                chmin(mini,ml+mr+1);
            }
            cout << "Yes" << ' ' << mini;
        }
    }
    else cout << "No";
}

/*



 */

Submission Info

Submission Time
Task B - 10 puzzle
User lucky_space
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1875 Byte
Status AC
Exec Time 3 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 45
Set Name Test Cases
All 0-sample-1, 0-sample-2, 0-sample-3, 0-sample-4, 1-random-small-0, 1-random-small-1, 1-random-small-2, 1-random-small-3, 1-random-small-4, 2-random-large-0, 2-random-large-1, 2-random-large-2, 2-random-large-3, 2-random-large-4, 3-random-line-0, 3-random-line-1, 3-random-line-10, 3-random-line-11, 3-random-line-12, 3-random-line-13, 3-random-line-14, 3-random-line-15, 3-random-line-16, 3-random-line-2, 3-random-line-3, 3-random-line-4, 3-random-line-5, 3-random-line-6, 3-random-line-7, 3-random-line-8, 3-random-line-9, 4-zero-0, 4-zero-1, 4-zero-2, 5-no-0, 5-no-1, 5-no-2, 6-minimum-0, 6-minimum-1, 6-minimum-2, 9-hand-0, 9-hand-1, 9-hand-2, 9-hand-3, 9-hand-4
Case Name Status Exec Time Memory
0-sample-1 AC 1 ms 256 KB
0-sample-2 AC 1 ms 256 KB
0-sample-3 AC 1 ms 256 KB
0-sample-4 AC 1 ms 256 KB
1-random-small-0 AC 1 ms 256 KB
1-random-small-1 AC 1 ms 256 KB
1-random-small-2 AC 1 ms 256 KB
1-random-small-3 AC 1 ms 256 KB
1-random-small-4 AC 1 ms 256 KB
2-random-large-0 AC 3 ms 256 KB
2-random-large-1 AC 3 ms 256 KB
2-random-large-2 AC 3 ms 256 KB
2-random-large-3 AC 3 ms 256 KB
2-random-large-4 AC 3 ms 256 KB
3-random-line-0 AC 1 ms 256 KB
3-random-line-1 AC 1 ms 256 KB
3-random-line-10 AC 1 ms 256 KB
3-random-line-11 AC 1 ms 256 KB
3-random-line-12 AC 1 ms 256 KB
3-random-line-13 AC 1 ms 256 KB
3-random-line-14 AC 1 ms 256 KB
3-random-line-15 AC 1 ms 256 KB
3-random-line-16 AC 1 ms 256 KB
3-random-line-2 AC 1 ms 256 KB
3-random-line-3 AC 1 ms 256 KB
3-random-line-4 AC 1 ms 256 KB
3-random-line-5 AC 1 ms 256 KB
3-random-line-6 AC 1 ms 256 KB
3-random-line-7 AC 1 ms 256 KB
3-random-line-8 AC 1 ms 256 KB
3-random-line-9 AC 1 ms 256 KB
4-zero-0 AC 3 ms 256 KB
4-zero-1 AC 1 ms 256 KB
4-zero-2 AC 1 ms 256 KB
5-no-0 AC 3 ms 256 KB
5-no-1 AC 1 ms 256 KB
5-no-2 AC 1 ms 256 KB
6-minimum-0 AC 1 ms 256 KB
6-minimum-1 AC 1 ms 256 KB
6-minimum-2 AC 1 ms 256 KB
9-hand-0 AC 1 ms 256 KB
9-hand-1 AC 1 ms 256 KB
9-hand-2 AC 1 ms 256 KB
9-hand-3 AC 1 ms 256 KB
9-hand-4 AC 1 ms 256 KB