Submission #9445

# Submission time Handle Problem Language Result Execution time Memory
9445 2014-09-28T06:29:35 Z ainu7 Solve another chuck (kriii2_S) C++
4 / 4
32 ms 2792 KB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int R, C;
vector<string> res;
int arr[100][100];

void rotR(int i) {
  char temp[50];
      if (C > 1) { sprintf(temp, "rotR %d 1", i+1); res.push_back(temp); }
      int t = arr[i][C-1];
      for (int k=C-1; k>=1; k--) arr[i][k] = arr[i][k-1];
      arr[i][0] = t;
}

void negC() {
  char temp[50];
        sprintf(temp, "negC 1"); res.push_back(temp);
        for (int k=0; k<R; k++) arr[k][0] = -arr[k][0];
}

void rotC() {
  char temp[50];
      if (R > 1) { sprintf(temp, "rotC 1 1"); res.push_back(temp); }
      int t = arr[R-1][0];
      for (int k=R-1; k>=1; k--) arr[k][0] = arr[k-1][0];
      arr[0][0] = t;
}

void negR() {
  char temp[50];
        sprintf(temp, "negR 1"); res.push_back(temp);
        for (int k=0; k<C; k++) arr[0][k] = -arr[0][k];
}

int main()
{
  cin >> R >> C;
  for (int i=0; i<R; i++)
    for (int j=0; j<C; j++)
      cin >> arr[i][j];

  for (int i=0; i<R; i++) {
    for (int j=0; j<C; j++) {
      rotR(i);

      if (arr[i][0] < 0) negC();
    }
    int idx = 0;
    for (int j=1; j<C; j++) if (abs(arr[i][j]) < abs(arr[i][idx])) idx = j;
    for (int iter=0; iter<C-idx; iter++) rotR(i);
  }

  int tog = 0;
  {
    for (int j=0; j<R; j++) {
      rotC();

      if (arr[0][0] < 0) negR(), tog = 1 - tog;
    }
    if (tog) {
      int idx = 0;
      for (int j=1; j<R; j++) if (abs(arr[j][0]) < abs(arr[idx][0])) idx = j;
      for (int iter=0; iter<R-idx; iter++) rotC();
      negR();
    }
  }

  if (arr[0][0] < 0) {
    if (R%2) {
      negC();
      for (int i=0; i<R-1; i++) {
        rotC();
        negR();
      }
    } else if (C%2) {
      negR();
      for (int i=0; i<C-1; i++) {
        rotR(0);
        negC();
      }
    }
  }

  int r = 0;
  for (int i=0; i<R; i++) for (int j=0; j<C; j++) r += arr[i][j];
  printf("%d %d\n", r, res.size());
  for (int i=0; i<res.size(); i++) cout << res[i] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1720 KB Output is correct
2 Correct 0 ms 1720 KB Output is correct
3 Correct 0 ms 1720 KB Output is correct
4 Correct 4 ms 1720 KB Output is correct
5 Correct 4 ms 1720 KB Output is correct
6 Correct 0 ms 1720 KB Output is correct
7 Correct 0 ms 1720 KB Output is correct
8 Correct 4 ms 2008 KB Output is correct
9 Correct 20 ms 2272 KB Output is correct
10 Correct 12 ms 2404 KB Output is correct
11 Correct 32 ms 2272 KB Output is correct
12 Correct 12 ms 2272 KB Output is correct
13 Correct 28 ms 2536 KB Output is correct
14 Correct 28 ms 2404 KB Output is correct
15 Correct 8 ms 2272 KB Output is correct
16 Correct 12 ms 2404 KB Output is correct
17 Correct 20 ms 2272 KB Output is correct
18 Correct 24 ms 2272 KB Output is correct
19 Correct 16 ms 2272 KB Output is correct
20 Correct 20 ms 2792 KB Output is correct
21 Correct 8 ms 2140 KB Output is correct
22 Correct 16 ms 2272 KB Output is correct
23 Correct 12 ms 2404 KB Output is correct
24 Correct 12 ms 2272 KB Output is correct
25 Correct 12 ms 2272 KB Output is correct
26 Correct 8 ms 2272 KB Output is correct
27 Correct 0 ms 1720 KB Output is correct
28 Correct 0 ms 1720 KB Output is correct
29 Correct 24 ms 2404 KB Output is correct
30 Correct 12 ms 2272 KB Output is correct