Fu_L's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Fu-L/cp-library

:heavy_check_mark: verify/aizu_online_judge/others/0502.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/0502"
#include "../../../src/template/template.hpp"
#include "../../../src/others/dice.hpp"
int main(void) {
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        Dice d;
        int ans = 1;
        while(n--) {
            string s;
            cin >> s;
            if(s == "North") d.roll_back();
            if(s == "East") d.roll_right();
            if(s == "South") d.roll_front();
            if(s == "West") d.roll_left();
            if(s == "Right") d.roll_cw();
            if(s == "Left") d.roll_ccw();
            ans += d.top;
        }
        cout << ans << '\n';
    }
}
#line 1 "verify/aizu_online_judge/others/0502.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/0502"
#line 2 "src/template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
#define rep(i, a, b) for(long long i = (a); i < (b); ++i)
#define rrep(i, a, b) for(long long i = (a); i >= (b); --i)
constexpr long long inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
#line 3 "src/others/dice.hpp"
#define roll_swap(x, a, b, c, d) swap(x.a, x.b), swap(x.b, x.c), swap(x.c, x.d);
struct Dice {
    int top, front, right, left, back, bottom;
    Dice(const int to = 1, const int fr = 2, const int ri = 3, const int le = 4, const int ba = 5, const int bo = 6)
        : top(to), front(fr), right(ri), left(le), back(ba), bottom(bo) {}
    void roll_right() {
        roll_swap((*this), top, left, bottom, right);
    }
    void roll_left() {
        roll_swap((*this), top, right, bottom, left);
    }
    void roll_front() {
        roll_swap((*this), top, back, bottom, front);
    }
    void roll_back() {
        roll_swap((*this), top, front, bottom, back);
    }
    void roll_cw() {
        roll_swap((*this), back, left, front, right);
    }
    void roll_ccw() {
        roll_swap((*this), back, right, front, left);
    }
    void roll(const int dir) {
        if(dir == 0) (*this).roll_front();
        if(dir == 1) (*this).roll_right();
        if(dir == 2) (*this).roll_back();
        if(dir == 3) (*this).roll_left();
    }
    friend bool operator<(const Dice& d1, const Dice& d2) {
        int vd1[] = {d1.top, d1.front, d1.right, d1.left, d1.back, d1.bottom};
        int vd2[] = {d2.top, d2.front, d2.right, d2.left, d2.back, d2.bottom};
        return vector<int>(vd1, vd1 + 6) < vector<int>(vd2, vd2 + 6);
    }
};

vector<Dice> all_rotate() {
    vector<Dice> res;
    res.reserve(24);
    Dice d;
    for(int i = 0; i < 6; ++i) {
        for(int j = 0; j < 4; ++j) {
            res.emplace_back(d);
            d.roll_cw();
        }
        if(i & 1) d.roll_front();
        else d.roll_right();
    }
    return res;
}
#line 4 "verify/aizu_online_judge/others/0502.test.cpp"
int main(void) {
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        Dice d;
        int ans = 1;
        while(n--) {
            string s;
            cin >> s;
            if(s == "North") d.roll_back();
            if(s == "East") d.roll_right();
            if(s == "South") d.roll_front();
            if(s == "West") d.roll_left();
            if(s == "Right") d.roll_cw();
            if(s == "Left") d.roll_ccw();
            ans += d.top;
        }
        cout << ans << '\n';
    }
}
Back to top page