Submission #1349657


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1000010

int dx[8] = {0,0,1,-1,1,1,-1,-1};
int dy[8] = {1,-1,0,0,1,-1,1,-1};

struct PLACE{
  PLACE *p[4];
  int x;
  int y;
  bool visited;

  PLACE(int x, int y):x(x), y(y), visited(false){
    for(int i=0;i<4;i++) p[i] = NULL;
  }
};


map<pair<int,int>, PLACE*> ss;

PLACE* add_place(int x, int y){
  auto it = ss.find({x,y});
  PLACE *r;
  if(it == ss.end()){
    r = new PLACE(x,y);
    ss[make_pair(x,y)] = r;

    for(int i=0;i<4;i++){
      auto it2 = ss.find({x+dx[i],y+dy[i]});
      if(it2 != ss.end()){
        r->p[i] = it2->second;

        if(r->p[i]->visited)
          r->p[i]->p[i/2*2+(1-i%2)] = r;
        
        if(r->p[i]->visited && r->p[i]->p[i] != NULL)
          r->p[i] = r->p[i]->p[i];
      }

      if(r->visited && r->p[0] != NULL && r->p[1] != NULL){
        r->p[0]->p[1] = r->p[1];
        r->p[1]->p[0] = r->p[0];
      }
      if(r->visited && r->p[2] != NULL && r->p[3] != NULL){
        r->p[2]->p[3] = r->p[3];
        r->p[3]->p[2] = r->p[2];
      }
    }
  }else{
    r = it->second;
  }

  return r;
}

int main(){
  int n;
  char s[SIZE];
  
  scanf("%d%s",&n,s);

  
  PLACE *now = add_place(0,0);
  
  for(int i=0;i<n;i++){
    now->visited = true;
    int g;

    if(s[i] == 'R') g = 2;
    if(s[i] == 'L') g = 3;
    if(s[i] == 'U') g = 0;
    if(s[i] == 'D') g = 1;
    
    while(now->visited){
      add_place(now->x+dx[g],now->y+dy[g]);
      now = now->p[g];
    }
  }

  printf("%d %d\n",now->x, now->y);
  
  return 0;
}

Submission Info

Submission Time
Task C - 幼稚園児高橋君
User goodbaton
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2125 Byte
Status TLE
Exec Time 4204 ms
Memory 25472 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:87:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%s",&n,s);
                     ^

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 0 / 100
Status
AC × 3
AC × 19
TLE × 5
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt
Subtask1 subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask0_sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 194 ms 25472 KB
subtask1_08.txt AC 191 ms 25472 KB
subtask1_09.txt AC 208 ms 25472 KB
subtask1_10.txt AC 178 ms 25472 KB
subtask1_11.txt AC 199 ms 25472 KB
subtask1_12.txt AC 213 ms 25472 KB
subtask1_13.txt AC 197 ms 25472 KB
subtask1_14.txt AC 303 ms 25472 KB
subtask1_15.txt AC 334 ms 25472 KB
subtask1_16.txt AC 329 ms 25472 KB
subtask1_17.txt TLE 4204 ms 3328 KB
subtask1_18.txt TLE 4204 ms 2176 KB
subtask1_19.txt TLE 4203 ms 2176 KB
subtask1_20.txt TLE 4204 ms 2944 KB
subtask1_21.txt TLE 4204 ms 3840 KB