Submission #9420

# Submission time Handle Problem Language Result Execution time Memory
9420 2014-09-28T06:17:54 Z ainu7 Solve another chuck (kriii2_S) C++
0 / 4
0 ms 1680 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 main()
{
  int R, C;
  cin >> R >> C;
  int arr[100][100] = {0};
  for (int i=0; i<R; i++)
    for (int j=0; j<C; j++)
      cin >> arr[i][j];

  vector<string> res;
  char temp[50];

  for (int i=0; i<R; i++) {
    for (int j=0; j<C; j++) {
      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;

      if (t < 0) {
        sprintf(temp, "negC 1"); res.push_back(temp);
        for (int k=0; k<R; k++) arr[k][0] = -arr[k][0];
      }
    }
    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++) {
      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;
    }
  }

  int tog = 0;
  {
    for (int j=0; j<R; j++) {
      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;

      if (t < 0) {
        sprintf(temp, "negR 1"); res.push_back(temp);
        for (int k=0; k<C; k++) arr[0][k] = -arr[0][k];
        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++) {
        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;
      }
      sprintf(temp, "negR 1"); res.push_back(temp);
      for (int k=0; k<C; k++) arr[0][k] = -arr[0][k];
    }
  }

  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 Incorrect 0 ms 1680 KB Output isn't correct
2 Halted 0 ms 0 KB -