Submission #674569


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)
using Integer = long long;
using Real = long double;
const Real PI = acosl(-1);
using P = pair<int, int>;

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class T, class U> inline
ostream& operator<<(ostream&os, tuple<T,U> t) {
  return os << '(' << get<0>(t) << ", " << get<1>(t) << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, set<T> v) {
  os << "(set"; for (T item: v) os << ' ' << item; os << ")"; return os;
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) return os << "(empty)";
  os << v[0]; for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i]; return is;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
const string Takahashi = "Takahashi";
const string Aoki = "Aoki";

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  int n=0;
  int x=0,y=0;
  string s; cin >> s;
  for (char c: s) {
    if (c=='U') x+=1;
    else if (c=='D') x-=1;
    else if (c=='L') y+=1;
    else if (c=='R') y-=1;
    else ++n;
  }
  int t; cin >> t;

  int mn = 2e9;
  int mx = -1;
  
  int i,j;
  {
    i=x-n; j=y;
    while (i<=x) {
      int d = abs(i)+abs(j); mn = min(mn, d); mx = max(mx, d);
      ++i; --j;
    }
  }

  {
    i=x+n; j=y;
    while (i>=x) {
      int d = abs(i)+abs(j); mn = min(mn, d); mx = max(mx, d);
      --i; --j;
    }
  }
  {
    i=x-n; j=y;
    while (i<=x) {
      int d = abs(i)+abs(j); mn = min(mn, d); mx = max(mx, d);
      ++i; ++j;
    }
  }
  {
    i=x+n; j=y;
    while (i>=x) {
      int d = abs(i)+abs(j); mn = min(mn, d); mx = max(mx, d);
      --i; ++j;
    }
  }

  cout << (t == 1 ? mx : mn) << endl;

  return 0;
}

Submission Info

Submission Time
Task B - ドローン
User cympfh
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2602 Byte
Status
Exec Time 7 ms
Memory 512 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt
Subtask1 100 / 100 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 20_no_question_01.txt, 20_no_question_02.txt, 20_no_question_03.txt, 20_no_question_04.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt
All 0 / 1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 20_no_question_01.txt, 20_no_question_02.txt, 20_no_question_03.txt, 20_no_question_04.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 70_no_ques_01.txt, 70_no_ques_02.txt, 70_no_ques_03.txt, 70_no_ques_04.txt, 80_max_01.txt, 80_max_02.txt, 80_max_03.txt, 80_max_04.txt, 90_corner_01.txt, 90_corner_02.txt, 90_corner_03.txt, 90_corner_04.txt
Case Name Status Exec Time Memory
00_example_01.txt 4 ms 256 KB
00_example_02.txt 4 ms 256 KB
00_example_03.txt 4 ms 256 KB
00_example_04.txt 4 ms 256 KB
10_rand_01.txt 4 ms 256 KB
10_rand_02.txt 4 ms 256 KB
10_rand_03.txt 4 ms 256 KB
10_rand_04.txt 4 ms 256 KB
20_no_question_01.txt 4 ms 256 KB
20_no_question_02.txt 4 ms 256 KB
20_no_question_03.txt 4 ms 256 KB
20_no_question_04.txt 4 ms 256 KB
30_max_01.txt 6 ms 512 KB
30_max_02.txt 6 ms 512 KB
30_max_03.txt 6 ms 512 KB
30_max_04.txt 6 ms 512 KB
40_corner_01.txt 6 ms 512 KB
40_corner_02.txt 7 ms 512 KB
40_corner_03.txt 6 ms 512 KB
40_corner_04.txt 6 ms 512 KB
50_hand_01.txt 4 ms 256 KB
50_hand_02.txt 4 ms 256 KB
50_hand_03.txt 4 ms 256 KB
60_rand_01.txt 4 ms 256 KB
60_rand_02.txt 4 ms 256 KB
60_rand_03.txt 4 ms 256 KB
60_rand_04.txt 4 ms 256 KB
70_no_ques_01.txt 4 ms 256 KB
70_no_ques_02.txt 4 ms 256 KB
70_no_ques_03.txt 4 ms 256 KB
70_no_ques_04.txt 4 ms 256 KB
80_max_01.txt 6 ms 512 KB
80_max_02.txt 6 ms 512 KB
80_max_03.txt 6 ms 512 KB
80_max_04.txt 6 ms 512 KB
90_corner_01.txt 7 ms 512 KB
90_corner_02.txt 7 ms 512 KB
90_corner_03.txt 6 ms 512 KB
90_corner_04.txt 6 ms 512 KB