Submission #4532152


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int n, m;

void prians(int answer) {
  if(answer >= 0)
    cout << "Yes " << answer << endl;
  else
    cout << "No" << endl;
}

int solve();
int calc(int x);

int main() {
  cin >> n >> m;
  prians(solve());
  return 0;
}

int solve() {
  bool chfive = 0;
  int maxnum = 0;
  if(n != 1 && m != 1) {
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < m; ++j) {
        int a;
        cin >> a;
        if(a == 5) chfive = 1;
        maxnum = max(maxnum, a);
      }
    if(!chfive && maxnum != 0) return -1;
    return calc(maxnum) + (maxnum >= 5);
  }
  if(n != 1) swap(n, m);
  vector<int> a(m, 0);
  int fi = -1, la = -1, num[2] = {0}, ans = 1;
  for(int i = 0; i < m; ++i) {
    cin >> a[i];
    if(a[i] == 5) {
      la = i;
      if(fi == -1) fi = i;
    }
    maxnum = max(maxnum, a[i]);
  }
  if(maxnum == 0) return 0;
  if(fi == -1) return -1;
  for(int i = 0; i < fi; ++i) num[0] = max(num[0], a[i]);
  for(int i = la + 1; i < m; ++i)
    num[1] = max(num[1], a[i]);
  num[0] = min(num[0], num[1]);
  ans += calc(maxnum) + calc(num[0]);
  return ans;
}

int calc(int x) {
  switch(x) {
    case 6:
    case 7: return 1; break;
    case 8: return 2; break;
    case 9: return 3; break;
  }
  return 0;
}

Submission Info

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

Test Cases

Set Name Score / Max Score Test Cases
All 100 / 100 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 1 ms 256 KB
0-sample-2 1 ms 256 KB
0-sample-3 1 ms 256 KB
0-sample-4 1 ms 256 KB
1-random-small-0 1 ms 256 KB
1-random-small-1 1 ms 256 KB
1-random-small-2 1 ms 256 KB
1-random-small-3 1 ms 256 KB
1-random-small-4 1 ms 256 KB
2-random-large-0 3 ms 256 KB
2-random-large-1 3 ms 256 KB
2-random-large-2 3 ms 256 KB
2-random-large-3 3 ms 256 KB
2-random-large-4 3 ms 256 KB
3-random-line-0 1 ms 256 KB
3-random-line-1 1 ms 256 KB
3-random-line-10 1 ms 256 KB
3-random-line-11 1 ms 256 KB
3-random-line-12 1 ms 256 KB
3-random-line-13 1 ms 256 KB
3-random-line-14 1 ms 256 KB
3-random-line-15 1 ms 256 KB
3-random-line-16 1 ms 256 KB
3-random-line-2 1 ms 256 KB
3-random-line-3 1 ms 256 KB
3-random-line-4 1 ms 256 KB
3-random-line-5 1 ms 256 KB
3-random-line-6 1 ms 256 KB
3-random-line-7 1 ms 256 KB
3-random-line-8 1 ms 256 KB
3-random-line-9 1 ms 256 KB
4-zero-0 3 ms 256 KB
4-zero-1 1 ms 256 KB
4-zero-2 1 ms 256 KB
5-no-0 3 ms 256 KB
5-no-1 1 ms 256 KB
5-no-2 1 ms 256 KB
6-minimum-0 1 ms 256 KB
6-minimum-1 1 ms 256 KB
6-minimum-2 1 ms 256 KB
9-hand-0 1 ms 256 KB
9-hand-1 1 ms 256 KB
9-hand-2 1 ms 256 KB
9-hand-3 1 ms 256 KB
9-hand-4 1 ms 256 KB