CSES - Leirikisa 5 - Results
Submission details
Task:baka
Sender:Kuha
Submission time:2016-08-03 10:06:05 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.15 sdetails
#20.13 sdetails
#30.14 sdetails
#40.13 sdetails
#50.13 sdetails
#60.15 sdetails
#70.14 sdetails
#80.14 sdetails
#90.15 sdetails
#100.15 sdetails
#110.14 sdetails
#120.14 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:91:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (j == ct[i].size()) j = x;
                        ^
input/code.cpp:96:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if (j == ct[i].size()) j = x;
                          ^
input/code.cpp:110:58: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < k; i++) if (iter[i] == q[i].size()) cout<<-1<<endl, exit(0);
                                                          ^

Code

#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define LINF 999999999999999999LL
#define N (1<<20)
#define M 1000000007

#define MAX 1000000
using namespace std;

int v[55][55][5];
int vx[5];
int vy[5];
int d[5];
int t[5];
bool cy[5][4];
vector<pair<int, int>> ct[5];
int fo[5];
vector<int> q[5];
int iter[5];

int main () {
  int n, m, k;
  cin>>n>>m>>k;
  int r, c;
  cin>>r>>c;
  for (int i = 0; i < k; i++) {
    char c;
    cin>>vy[i]>>vx[i]>>c;
    if (c == 'L') d[i] = 0;
    if (c == 'U') d[i] = 1;
    if (c == 'R') d[i] = 2;
    if (c == 'D') d[i] = 3;
    for (int y = 1; y <= n; y++) {
      for (int x = 1; x <= m; x++) {
        cin>>c;
	v[y][x][i] = c - '0';
      }
    }
  }
  for (int i = 0; i < k; i++) {
    int l = 1;
    int qa = MAX;
    int ts = 1;
    while (qa--) {
      l++;
      ts++;
      int X = v[vy[i]][vx[i]][i];
      int x = vx[i];
      int y = vy[i];
      d[i] = (d[i] + X) % 4;
      if (d[i] == 0 && x == 1) d[i] = 2;
      else if (d[i] == 1 && y == 1) d[i] = 3;
      else if (d[i] == 2 && x == m) d[i] = 0;
      else if (d[i] == 3 && y == n) d[i] = 1;
      if (d[i] == 0) vx[i] -= 1;
      if (d[i] == 1) vy[i] -= 1;
      if (d[i] == 2) vx[i] += 1;
      if (d[i] == 3) vy[i] += 1;
      if (vy[i] == r && vx[i] == c) {
	t[i] = l;
	q[i].push_back(-l);
	break;
      }
    }
    if (qa <= 0) cout<<-1<<endl, exit(0);
    l = 0;
    while (qa--) {
      ts++;
      l++;
      int X = v[vy[i]][vx[i]][i];
      int x = vx[i];
      int y = vy[i];
      d[i] = (d[i] + X) % 4;
      if (d[i] == 0 && x == 1) d[i] = 2;
      else if (d[i] == 1 && y == 1) d[i] = 3;
      else if (d[i] == 2 && x == m) d[i] = 0;
      else if (d[i] == 3 && y == n) d[i] = 1;
      if (d[i] == 0) vx[i] -= 1;
      if (d[i] == 1) vy[i] -= 1;
      if (d[i] == 2) vx[i] += 1;
      if (d[i] == 3) vy[i] += 1;
      if (vy[i] == r && vx[i] == c) {
	if (cy[i][d[i]]) {
	  fo[i] = d[i];
	  int x = 0;
	  for (; x < 4; x++) {
	    if (ct[i][x].second == d[i]) break;
	  }
	  int j = x + 1;
	  if (j == ct[i].size()) j = x;
	  for (int w = 0; w < 6000000; w++) {
	    q[i].push_back(-ts);
	    ts += ct[i][j].first;
	    j++;
	    if (j == ct[i].size()) j = x;
	  }
	  break;
	}
	else {
	  cy[i][d[i]] = 1;
	  ct[i].push_back({l, d[i]});
	  q[i].push_back(-ts);
	  l = 0;
	}
      }
    }
  }
  while (true) {
    for (int i = 0; i < k; i++) if (iter[i] == q[i].size()) cout<<-1<<endl, exit(0);
    //for (int i = 0; i < k; i++) cout<<-q[i].top()<<" ";
    //cout<<endl;
    int x = q[0][iter[0]];
    bool b = true;
    for (int i = 1; i < k; i++) {
      if (q[i][iter[i]] != x) {
	if (q[i][iter[i]] < x) iter[0]++;
	else iter[i]++;
	b = false;
	break;
      }
    }
    if (b) cout<<-x<<endl, exit(0);
  }
}

Test details

Test 1

Verdict:

input
WA

correct output
13

user output
(empty)

Test 2

Verdict:

input
UNUCIC

correct output
36

user output
(empty)

Test 3

Verdict:

input
MACDNKIHFGBEHOJ

correct output
74

user output
(empty)

Test 4

Verdict:

input
ABCDEFGHIJKLMNO

correct output
75

user output
(empty)

Test 5

Verdict:

input
NCC

correct output
13

user output
(empty)

Test 6

Verdict:

input
AUUI

correct output
26

user output
(empty)

Test 7

Verdict:

input
UOEAIAOIUE

correct output
56

user output
(empty)

Test 8

Verdict:

input
AOEUIIUEAOEAOIO

correct output
82

user output
(empty)

Test 9

Verdict:

input
CFILOSVZXQCPFZO

correct output
102

user output
(empty)

Test 10

Verdict:

input
BEHKNRUYKRUBNE

correct output
89

user output
(empty)

Test 11

Verdict:

input
ADGJMPTWTPMJGDA

correct output
94

user output
(empty)

Test 12

Verdict:

input
UNUCICA

correct output
39

user output
(empty)