CSES - Leirikisa 4 - Results
Submission details
Task:misa
Sender:Hansuzu
Submission time:2016-08-01 15:17:00 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.06 sdetails
#6ACCEPTED0.06 sdetails
#7ACCEPTED0.05 sdetails

Code

#include <iostream>
using namespace std;
int S, R;

string r[55];

int h(int i, int j){
  if (i<0 || i>=R || j<0 || j>=S || r[i][j]=='.') return 0;
  return 1;
}

int k(int x, int y){
  int rv=-h(x, y);
  for (int i=-1; i<=1; ++i)
    for (int j=-1; j<=1; ++j)
      rv+=h(x+i, y+j);
  return rv;
}


int main(){
  cin >> R >> S;
  for (int i=0; i<R; ++i)  cin >> r[i];
  
  int mxk=0;
  int ans=0;
  for (int i=0; i<R; ++i){
    for (int j=0; j<S; ++j){
      if (r[i][j]=='o') ans+=k(i, j);
      else              mxk=max(mxk, k(i, j));
    }
  }
  cout << ans/2+mxk << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
2 3
..o
o..

correct output
2

user output
2

Test 2

Verdict: ACCEPTED

input
2 2
oo
oo

correct output
6

user output
6

Test 3

Verdict: ACCEPTED

input
1 23
o..oo.ooooo..o.oooo.ooo

correct output
12

user output
12

Test 4

Verdict: ACCEPTED

input
2 20
..oooooo.oo.....o.oo
ooooooooo.o.ooo..ooo

correct output
50

user output
50

Test 5

Verdict: ACCEPTED

input
21 11
ooooooooooo
ooooooooooo
ooooooooooo
ooooooooooo
...

correct output
830

user output
830

Test 6

Verdict: ACCEPTED

input
28 8
........
.oo..oo.
..oo....
..o.o...
...

correct output
53

user output
53

Test 7

Verdict: ACCEPTED

input
49 50
ooo....oooo.oooo...o..o.oooooo...

correct output
4248

user output
4248