CSES - Leirikisa 5 - Results
Submission details
Task:bakterije
Sender:Kuha
Submission time:2016-08-02 17:51:54 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.05 sdetails
#6--details
#70.06 sdetails
#80.06 sdetails
#90.06 sdetails
#100.06 sdetails
#110.06 sdetails
#120.06 sdetails
#130.06 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:90:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (j == ct[i].size()) j = x;
                        ^
input/code.cpp:95:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if (j == ct[i].size()) j = x;
                          ^

Code

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

#define MAX 10000
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];
priority_queue<int> q[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(-l);
	break;
      }
    }
    if (!qa) 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 < 50000; w++) {
	    q[i].push(-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(-ts);
	  l = 0;
	}
      }
    }
  }
  while (true) {
    for (int i = 0; i < k; i++) if (q[i].empty()) cout<<-1<<endl, exit(0);
    //for (int i = 0; i < k; i++) cout<<-q[i].top()<<" ";
    //cout<<endl;
    int x = q[0].top();
    bool b = true;
    for (int i = 1; i < k; i++) {
      if (q[i].top() != x) {
	if (q[i].top() < x) q[0].pop();
	else q[i].pop();
	b = false;
	break;
      }
    }
    if (b) cout<<-x<<endl, exit(0);
  }
}

Test details

Test 1

Verdict: ACCEPTED

input
3 3 1
2 2
1 1 R
010
000
...

correct output
3

user output
3

Test 2

Verdict: ACCEPTED

input
3 4 2
2 2
3 4 R
2327
6009
...

correct output
8

user output
8

Test 3

Verdict: ACCEPTED

input
4 4 3
4 3
1 1 U
1001
0240
...

correct output
296

user output
296

Test 4

Verdict: ACCEPTED

input
10 10 2
2 2
10 10 D
3000000003
3240082600
...

correct output
31

user output
31

Test 5

Verdict: ACCEPTED

input
20 20 3
18 8
18 14 L
52076326768887743424
30953273223516230377
...

correct output
127365

user output
127365

Test 6

Verdict:

input
16 24 3
1 1
9 15 L
386703035230234125771793
410163209210321990377031
...

correct output
-1

user output
(empty)

Test 7

Verdict:

input
35 39 4
11 23
35 10 D
534119390852214853015480726815...

correct output
68430452

user output
-1

Test 8

Verdict:

input
21 32 5
3 5
15 8 R
334126231002222122244321129954...

correct output
1959913839402

user output
-1

Test 9

Verdict:

input
29 44 5
20 21
3 26 L
760376683503757740684647181292...

correct output
62013683483

user output
-1

Test 10

Verdict:

input
40 40 5
28 23
15 9 L
137103427205590752679014023441...

correct output
57788077454

user output
-1

Test 11

Verdict:

input
45 49 5
12 15
34 30 R
860736165053314133032790918044...

correct output
10477495826046

user output
-1

Test 12

Verdict:

input
47 49 5
17 26
8 40 R
384608891563515730952391281457...

correct output
781942227216

user output
-1

Test 13

Verdict:

input
50 50 5
4 35
27 43 L
998166911112259286230836653527...

correct output
9298781157357368

user output
-1