Submission #49090106
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
// 型・メソッド・イテレータ系
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define drep(i, n) for(int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < (t); ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define bg begin
#define ed end
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define snuke_san srand((unsigned)clock()+(unsigned)time(NULL));
#define newline puts("")
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using uint = unsigned; using ll = long long; using ull = unsigned long long; using ld = long double;
using P = pair<int, int>; using lp = pair<ll, ll>; using lt = tuple<ll, ll, ll>;
using vi = vc<int>; using vvi = vv<int>; using vvvi = vv<vi>;
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>;
using vch = vc<char>; using vvch = vv<char>; using vs = vc<string>; using vvs = vc<vs>;
// 入出力系
template<typename Tx, typename Ty>istream& operator>>(istream&i, pair<Tx, Ty>&v){return i>>v.fi>>v.se;}
template<typename Tx, typename Ty>ostream& operator<<(ostream&o, const pair<Tx, Ty>&v){return o<<v.fi<<", "<<v.se;}
template<typename T>istream& operator>>(istream&i, vc<T>&v){rep(j, sz(v))i>>v[j];return i;}
template<typename T>string join(const T&v, const string& d=""){stringstream s;rep(i, sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<typename T>ostream& operator<<(ostream&o, const vc<T>&v){if(sz(v))o<<join(v, " ");return o;}
#define iint(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define ill(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define ich(...) char __VA_ARGS__; IN(__VA_ARGS__)
#define istr(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define ild(...) ld __VA_ARGS__; IN(__VA_ARGS__)
#define ivc(type, name, size) vector<type> name(size); IN(name)
#define ivc2(type, name1, name2, size) vector<type> name1(size), name2(size); for(int i = 0; i < size; i++) IN(name1[i], name2[i])
#define ivc3(type, name1, name2, name3, size) vector<type> name1(size), name2(size), name3(size); for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i])
#define ivc4(type, name1, name2, name3, name4, size) vector<type> name1(size), name2(size), name3(size), name4(size); for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i], name4[i]);
#define ivv(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); IN(name)
void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; }
template <typename T> void scan(T &a) { cin >> a; }
template <typename T, typename S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <typename T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
void IN() {} template <typename Head, typename... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); }
#define ortn(...) { out(__VA_ARGS__); return 0; }
#define dame { puts("-1"); return 0; }
#define yes { puts("Yes"); return 0; }
#define no { puts("No"); return 0; }
#define yn(ok) { puts(ok ? "Yes" : "No"); }
void out() { cout << '\n'; } template <typename Head, typename... Tail> void out(const Head &head, const Tail &...tail) { cout << head; if(sizeof...(tail)) cout << ' '; out(tail...); }
// 数値系
template<typename T> int lbs(vector<T> &a, const T &b) { return lower_bound(all(a), b) - a.begin(); };
template<typename T> int ubs(vector<T> &a, const T &b) { return upper_bound(all(a), b) - a.begin(); };
template<typename Tx, typename Ty> Tx ceil(Tx x, Ty y) {assert(y);return (y<0 ? ceil(-x,-y) : (x>0 ? (x+y-1)/y : x/y));}
template<typename Tx, typename Ty> Tx floor(Tx x, Ty y) {assert(y);return (y<0 ? floor(-x,-y) : (x>0 ? x/y : (x-y+1)/y));}
template<typename T> ll sumof(const vc<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
template<typename T> ll sumof(const vv<T>&a){ll res(0);for(auto&&x:a)res+=sumof(x);return res;}
template<typename T> vc<T> csum(vc<T> &a) { vc<T> res(a.size() + 1, 0); rep(i, a.size()) res[i + 1] = res[i] + a[i]; return res; }
template<typename T> void prepend(vc<T>&a, const T&x){a.insert(a.bg(), x);}
// 操作系
template<typename Tx, typename Ty> void operator--(pair<Tx, Ty>&a, int){a.fi--;a.se--;}
template<typename Tx, typename Ty> void operator++(pair<Tx, Ty>&a, int){a.fi++;a.se++;}
template<typename T> void operator--(vc<T>&a, int){for(T&x:a)x--;}
template<typename T> void operator++(vc<T>&a, int){for(T&x:a)x++;}
template<typename T> void operator+=(vc<T>&a, T b){for(T&x:a)x+=b;}
template<typename T> void operator-=(vc<T>&a, T b){for(T&x:a)x-=b;}
template<typename T> void operator*=(vc<T>&a, T b){for(T&x:a)x*=b;}
template<typename T> void operator/=(vc<T>&a, T b){for(T&x:a)x/=b;}
template<typename T> void operator+=(vc<T>&a, const vc<T>&b){a.insert(a.ed(), all(b));}
template<typename Tx, typename Ty> bool chmin(Tx& x, const Ty&y){if(y<x){x=y;return true;}else return false;}
template<typename Tx, typename Ty> bool chmax(Tx& x, const Ty&y){if(x<y){x=y;return true;}else return false;}
template<typename T> void uni(T&a){sort(all(a));a.erase(unique(all(a)), a.ed());}
template<typename T> void cc(vc<T>&a){vc<T> b=a;uni(b);rep(i, a.size())a[i]=lbs(b, a[i]);}
template<typename T = ll> pair<unordered_map<ll, ll>, unordered_map<ll, ll>> ccmp(vector<T> &a) { vector<T> ca = a; cc(ca); unordered_map<ll, ll> res, rev; rep(i, ca.size()) { res[a[i]] = ca[i]; rev[ca[i]] = a[i]; } return make_pair(res, rev); }
template<typename T> vc<pair<T, int>> RLE(const vc<T> &v) { vc<pair<T, int>> res; for(auto &e : v) if(res.empty() or res.back().first != e) res.emplace_back(e, 1); else res.back().second++; return res; }
template<typename T> void rotate(vv<T> &a) { ll n = a.size(), m = a[0].size(); vv<T> res(m, vc<T>(n, 0)); rep(i, n) rep(j, m) res[j][n - 1 - i] = a[i][j]; a = res; }
vi pm(int n, int s=0) {vi a(n); iota(all(a), s); return a;}
// よく使う値
const int INF = 1001001001;
const ll INFL = 1001002003004005006ll;
const ld EPS = 1e-10;
const int dx[8] = {0, -1, 1, 0, 1, -1, -1, 1};
const int dy[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
int main() {
iint(n, q);
vc<P> memo = {{0, 0}};
rep(_, q) {
iint(t);
if (t == 1) {
ich(c);
int cdi = 0, cdj = 0;
if (c == 'R') cdj++;
if (c == 'L') cdj--;
if (c == 'U') cdi++;
if (c == 'D') cdi--;
memo.eb(cdi, cdj);
memo[sz(memo) - 1].fi += memo[sz(memo) - 2].fi;
memo[sz(memo) - 1].se += memo[sz(memo) - 2].se;
}
if (t == 2) {
iint(cp);
int ansi = (sz(memo) - 1 <= cp - 1 ? 0 : memo[max(0, sz(memo) - 1 - (cp - 1))].fi);
int ansj = cp + memo[max(0, sz(memo) - 1 - (cp - 1))].se - min(cp - 1, sz(memo) - 1);
out(ansj, ansi);
}
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Loong Tracking |
| User |
Chomusuke |
| Language |
C++ 20 (gcc 12.2) |
| Score |
300 |
| Code Size |
7063 Byte |
| Status |
AC |
| Exec Time |
241 ms |
| Memory |
5360 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
300 / 300 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt |
| All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt |
| Case Name |
Status |
Exec Time |
Memory |
| random_01.txt |
AC |
54 ms |
5200 KiB |
| random_02.txt |
AC |
53 ms |
5156 KiB |
| random_03.txt |
AC |
45 ms |
5164 KiB |
| random_04.txt |
AC |
33 ms |
4072 KiB |
| random_05.txt |
AC |
148 ms |
4156 KiB |
| random_06.txt |
AC |
147 ms |
4160 KiB |
| random_07.txt |
AC |
55 ms |
3852 KiB |
| random_08.txt |
AC |
26 ms |
3584 KiB |
| random_09.txt |
AC |
236 ms |
3584 KiB |
| random_10.txt |
AC |
238 ms |
3516 KiB |
| random_11.txt |
AC |
90 ms |
3568 KiB |
| random_12.txt |
AC |
74 ms |
3572 KiB |
| random_13.txt |
AC |
138 ms |
4160 KiB |
| random_14.txt |
AC |
1 ms |
3492 KiB |
| random_15.txt |
AC |
55 ms |
5164 KiB |
| random_16.txt |
AC |
54 ms |
5360 KiB |
| random_17.txt |
AC |
52 ms |
5120 KiB |
| random_18.txt |
AC |
53 ms |
5176 KiB |
| random_19.txt |
AC |
149 ms |
4100 KiB |
| random_20.txt |
AC |
147 ms |
4164 KiB |
| random_21.txt |
AC |
139 ms |
4172 KiB |
| random_22.txt |
AC |
148 ms |
4148 KiB |
| random_23.txt |
AC |
241 ms |
3556 KiB |
| random_24.txt |
AC |
237 ms |
3616 KiB |
| random_25.txt |
AC |
221 ms |
3772 KiB |
| random_26.txt |
AC |
237 ms |
3592 KiB |
| random_27.txt |
AC |
146 ms |
4100 KiB |
| random_28.txt |
AC |
145 ms |
4108 KiB |
| random_29.txt |
AC |
136 ms |
4208 KiB |
| random_30.txt |
AC |
144 ms |
4188 KiB |
| sample_01.txt |
AC |
1 ms |
3524 KiB |