RCO presents 日本橋ハーフマラソン 本戦

Submission #1358183

Source codeソースコード

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef long long int ll;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define repeat(l) for(auto cnt=0;cnt<(l);++cnt)
#define iterate(b,e) for(auto cnt=(b);cnt!=(e);++cnt)
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795
template<typename T1, typename T2>
ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())
namespace {
    std::chrono::system_clock::time_point ttt;
    void tic() { ttt = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - ttt)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}
#ifdef __MAI
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
#ifdef __VSCC
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
namespace {
#define isvisiablechar(c) (0x21<=(c)&&(c)<=0x7E)
    class MaiScanner {
    public:
        template<typename T>
        void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        inline MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
        inline MaiScanner& operator>>(string& var) {
            int cc = getchar_unlocked();
            for (; !isvisiablechar(cc); cc = getchar_unlocked());
            for (; isvisiablechar(cc); cc = getchar_unlocked())
                var.push_back(cc);
        }
    };
    class MaiPrinter {
        int stack_p;
        char stack[32];
    public:
        template<typename T>
        void output_integer(T var) {
            if (var == 0) {
                putchar_unlocked('0');
                return;
            }
            if (var < 0) {
                putchar_unlocked('-');
                var = -var;
            }
            stack_p = 0;
            while (var) {
                stack[stack_p++] = '0' + (var % 10);
                var /= 10;
            }
            while (stack_p)
                putchar_unlocked(stack[--stack_p]);
        }
        inline MaiPrinter& operator<<(char c) {
            putchar_unlocked(c);
            return *this;
        }
        inline MaiPrinter& operator<<(int var) {
            output_integer<int>(var);
            return *this;
        }
        inline MaiPrinter& operator<<(long long var) {
            output_integer<long long>(var);
            return *this;
        }
        inline MaiPrinter& operator<(int var) {
            output_integer<int>(var);
            putchar_unlocked(' ');
            return *this;
        }
        inline MaiPrinter& operator<(long long var) {
            output_integer<long long>(var);
            putchar_unlocked(' ');
            return *this;
        }
        inline MaiPrinter& operator<<(const string& str) {
            const char* p = str.c_str();
            const char* l = p + str.size();
            while (p < l) putchar_unlocked(*p++);
            return *this;
        }
    };
}
MaiScanner scanner;
MaiPrinter printer;



random_device noize;
mt19937 mt(noize());

int rand_int(int l, int h) {
    uniform_int_distribution<> range(l, h);
    return range(mt);
}



int height = 30, width = 30, n = 450, t_limit = 10000;

inline bool isscreenout(int y, int x) {
    return y < 0 || x < 0 || height <= y || width <= x;
}

inline char actvel2char(int vy, int vx) {
    return vx < 0 ? 'L' : vx>0 ? 'R' : vy < 0 ? 'U' : vy>0 ? 'D' : '-';
}

inline void actchar(int &y, int &x, int c) {
    if (c == 'L') --x;
    else if (c == 'R') ++x;
    else if (c == 'U') --y;
    else if (c == 'D') ++y;
}


class Car {
public:
    int y, x, dy, dx;
    Car(int y = 0, int x = 0, int dy = 0, int dx = 0) :y(y), x(x), dy(dy), dx(dx) {}
};

class State {
public:
    vector<int> data;
    vector<Car> cars;
    string acts;
    int turn;

    State() :data(width*height, -1), cars(n), acts(n, '-') {  }

    inline int& operator()(int y, int x) {
        return data[x + y*width];
    }
    inline int operator()(int y, int x) const {
        return data[x + y*width];
    }
    inline int& at(int y, int x) {
        return data[x + y*width];
    }
    inline int at(int y, int x) const {
        return data[x + y*width];
    }

    void put(int carid, int y, int x, int dx, int dy) {
        at(y, x) = carid;
        cars[carid] = Car(y, x, dx, dy);
    }

    bool action(int carid, int vy, int vx) {
        const Car& car = cars[carid];
        if (isscreenout(car.y + vy, car.x + vx)) return false;
        int& to = at(car.y + vy, car.x + vx);
        if (to != -1) return false;
        to = -2 - carid;
        acts[carid] = actvel2char(vy, vx);
        return true;
    }

    int act_count() const {
        int cnt = 0;
        for (char c : acts) {
            cnt += (c != '-');
        }
        return cnt;
    }

    // bool print() const {
    //     string s;
    //     bool b = false;
    //     for (char c : acts) {
    //         if (b |= (c != '-')) break;
    //     }
    //     if (!b) return false;
    //     printer << acts << '\n';
    //     return true;
    // }

    void eprint() const {
        printf("---\n");
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                printf("%4d", at(y, x));
            }
            printf("\n");
        }
    }

    State next_state() const {
        State new_state = *this;

        for (int i = 0; i < n; ++i) {
            Car &car = new_state.cars[i];

            new_state.at(car.y, car.x) = -1;
            actchar(car.y, car.x, new_state.acts[i]);
            new_state.at(car.y, car.x) = i;
        }
        fill(ALL(new_state.acts), '-');

        return new_state;
    }
};



State first_state;

list<State> result;

void solve_greedy() {

    State state = first_state;

    repeat(t_limit) {
        for (int i = 0; i < n; ++i) {
            Car &car = state.cars[i];
            int uy = car.dy - car.y;
            int ux = car.dx - car.x;
            
            bool pr = rand_int(0, 1);
            if (uy != 0 && (ux == 0 || pr)) {
                if (uy > 0) pr = state.action(i, 1, 0);
                else pr = state.action(i, -1, 0);
            }
            if (ux != 0 && (uy == 0 || !pr)) {
                if (ux > 0) state.action(i, 0, 1);
                else state.action(i, 0, -1);
            }
        }
        //state.eprint();
        if (state.act_count() < 5) break;

        result.push_back(state);

        state = state.next_state();
    }
}

int main(int argc, char** argv) {

    scanner >> height >> width >> n >> t_limit;

    repeat(n) {
        int a, b, c, d;
        scanner >> a >> b >> c >> d;
        first_state.put(cnt, --a, --b, --c, --d);
    }

    solve_greedy();


    printer << (int)result.size() << '\n';

    for (State& s : result) {
        printer << s.acts << '\n';
    }
    

    return 0;
}

Submission

Task問題 B - 日本橋大渋滞
User nameユーザ名 舞葉舞
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 4561
Source lengthソースコード長 8586 Byte
File nameファイル名
Exec time実行時間 2 ms
Memory usageメモリ使用量 768 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘void {anonymous}::toc()’:
./Main.cpp:26:73: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘std::chrono::duration<long int, std::ratio<1l, 1000l> >::rep {aka long int}’ [-Wformat=]
void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - ttt)); }
^

Test case

Set

Set name Score得点 / Max score Cases
test_01 157 / 50000 subtask_01_01.txt
test_02 150 / 50000 subtask_01_02.txt
test_03 155 / 50000 subtask_01_03.txt
test_04 157 / 50000 subtask_01_04.txt
test_05 171 / 50000 subtask_01_05.txt
test_06 154 / 50000 subtask_01_06.txt
test_07 151 / 50000 subtask_01_07.txt
test_08 160 / 50000 subtask_01_08.txt
test_09 144 / 50000 subtask_01_09.txt
test_10 144 / 50000 subtask_01_10.txt
test_11 159 / 50000 subtask_01_11.txt
test_12 154 / 50000 subtask_01_12.txt
test_13 146 / 50000 subtask_01_13.txt
test_14 159 / 50000 subtask_01_14.txt
test_15 151 / 50000 subtask_01_15.txt
test_16 156 / 50000 subtask_01_16.txt
test_17 145 / 50000 subtask_01_17.txt
test_18 145 / 50000 subtask_01_18.txt
test_19 148 / 50000 subtask_01_19.txt
test_20 149 / 50000 subtask_01_20.txt
test_21 158 / 50000 subtask_01_21.txt
test_22 152 / 50000 subtask_01_22.txt
test_23 154 / 50000 subtask_01_23.txt
test_24 144 / 50000 subtask_01_24.txt
test_25 146 / 50000 subtask_01_25.txt
test_26 158 / 50000 subtask_01_26.txt
test_27 150 / 50000 subtask_01_27.txt
test_28 142 / 50000 subtask_01_28.txt
test_29 153 / 50000 subtask_01_29.txt
test_30 149 / 50000 subtask_01_30.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask_01_01.txt AC 2 ms 768 KB
subtask_01_02.txt AC 2 ms 768 KB
subtask_01_03.txt AC 2 ms 640 KB
subtask_01_04.txt AC 2 ms 768 KB
subtask_01_05.txt AC 2 ms 640 KB
subtask_01_06.txt AC 2 ms 768 KB
subtask_01_07.txt AC 2 ms 640 KB
subtask_01_08.txt AC 2 ms 640 KB
subtask_01_09.txt AC 2 ms 768 KB
subtask_01_10.txt AC 2 ms 768 KB
subtask_01_11.txt AC 2 ms 640 KB
subtask_01_12.txt AC 2 ms 768 KB
subtask_01_13.txt AC 2 ms 640 KB
subtask_01_14.txt AC 2 ms 768 KB
subtask_01_15.txt AC 2 ms 768 KB
subtask_01_16.txt AC 2 ms 640 KB
subtask_01_17.txt AC 2 ms 768 KB
subtask_01_18.txt AC 2 ms 640 KB
subtask_01_19.txt AC 2 ms 768 KB
subtask_01_20.txt AC 2 ms 768 KB
subtask_01_21.txt AC 2 ms 640 KB
subtask_01_22.txt AC 2 ms 640 KB
subtask_01_23.txt AC 2 ms 768 KB
subtask_01_24.txt AC 2 ms 640 KB
subtask_01_25.txt AC 2 ms 768 KB
subtask_01_26.txt AC 2 ms 768 KB
subtask_01_27.txt AC 2 ms 768 KB
subtask_01_28.txt AC 2 ms 768 KB
subtask_01_29.txt AC 2 ms 768 KB
subtask_01_30.txt AC 2 ms 640 KB