AtCoder Regular Contest 039

Submission #1060689

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

struct Point {
  int x;
  int y;
  Point() {};
  Point(int x_, int y_) : x(x_), y(y_) {};
};

vi dx = {1, 0,  0, -1};
vi dy = {0, 1, -1,  0};

int main() {
  int k;
  scanf("%d", &k);
  map<char, int> ctoi;
  ctoi['R'] = 0;
  ctoi['U'] = 1;
  ctoi['L'] = 3;
  ctoi['D'] = 2;
  vi s(k);
  rep (i, k) {
    char tmp;
    scanf(" %c", &tmp);
    s[i] = ctoi[tmp];
  }
  map<vi, vi> mp;
  Point current(0, 0);
  rep (i, k) {
    rep (j, 2) {
      Point p_j, p_j_;
      int j_ = 3 - j;
      vi mpj = mp[{current.x, current.y, j}];
      vi mpj_ = mp[{current.x, current.y, j_}];
      if ((int)mpj.size() == 0) {
        p_j = Point(current.x + dx[j], current.y + dy[j]);
      } else {
        p_j = Point(mpj[0], mpj[1]);
      }
      if ((int)mpj_.size() == 0) {
        p_j_ = Point(current.x + dx[j_], current.y + dy[j_]);
      } else {
        p_j_ = Point(mpj_[0], mpj_[1]);
      }
      mp[{p_j.x, p_j.y, j_}].clear();
      mp[{p_j.x, p_j.y, j_}] = {p_j_.x, p_j_.y};
      mp[{p_j_.x, p_j_.y, j}].clear();
      mp[{p_j_.x, p_j_.y, j}] = {p_j.x, p_j.y};
    }

    vi mpj = mp[{current.x, current.y, s[i]}];
    if ((int)mpj.size() == 0) {
      current = Point(current.x + dx[s[i]], current.y + dy[s[i]]);
    } else {
      current = Point(mpj[0], mpj[1]);
    }
  }
  printf("%d %d\n", current.x, current.y);

  return 0;
}

Submission

Task問題 C - 幼稚園児高橋君
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++14 (Clang++ 3.4)
Status状態 AC
Score得点 100
Source lengthソースコード長 2293 Byte
File nameファイル名
Exec time実行時間 1196 ms
Memory usageメモリ使用量 170272 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample_01.txt,subtask0_sample_02.txt,subtask0_sample_03.txt
Subtask1 100 / 100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample_01.txt AC 18 ms 912 KB
subtask0_sample_02.txt AC 16 ms 796 KB
subtask0_sample_03.txt AC 16 ms 924 KB
subtask1_01.txt AC 16 ms 800 KB
subtask1_02.txt AC 16 ms 800 KB
subtask1_03.txt AC 16 ms 928 KB
subtask1_04.txt AC 18 ms 840 KB
subtask1_05.txt AC 17 ms 756 KB
subtask1_06.txt AC 17 ms 800 KB
subtask1_07.txt AC 849 ms 124192 KB
subtask1_08.txt AC 837 ms 124192 KB
subtask1_09.txt AC 843 ms 122408 KB
subtask1_10.txt AC 827 ms 125988 KB
subtask1_11.txt AC 845 ms 123160 KB
subtask1_12.txt AC 848 ms 122396 KB
subtask1_13.txt AC 872 ms 123844 KB
subtask1_14.txt AC 1196 ms 170268 KB
subtask1_15.txt AC 1049 ms 170272 KB
subtask1_16.txt AC 953 ms 142196 KB
subtask1_17.txt AC 805 ms 170268 KB
subtask1_18.txt AC 1146 ms 170264 KB
subtask1_19.txt AC 808 ms 144928 KB
subtask1_20.txt AC 768 ms 143528 KB
subtask1_21.txt AC 1081 ms 142108 KB