Submission #1358151


Source Code Expand

#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() < 10) 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 Info

Submission Time
Task B - 日本橋大渋滞
User m_buyoh
Language C++14 (GCC 5.4.1)
Score 4530
Code Size 8589 Byte
Status AC
Exec Time 2 ms
Memory 640 KB

Compile Error

./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)); }
                                                                         ^

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10 test_11 test_12 test_13 test_14 test_15 test_16 test_17 test_18 test_19 test_20 test_21 test_22 test_23 test_24 test_25 test_26 test_27 test_28 test_29 test_30
Score / Max Score 153 / 50000 153 / 50000 151 / 50000 158 / 50000 170 / 50000 155 / 50000 154 / 50000 157 / 50000 144 / 50000 151 / 50000 158 / 50000 153 / 50000 145 / 50000 156 / 50000 145 / 50000 160 / 50000 147 / 50000 145 / 50000 144 / 50000 150 / 50000 156 / 50000 151 / 50000 150 / 50000 141 / 50000 145 / 50000 156 / 50000 149 / 50000 137 / 50000 151 / 50000 145 / 50000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
test_11 subtask_01_11.txt
test_12 subtask_01_12.txt
test_13 subtask_01_13.txt
test_14 subtask_01_14.txt
test_15 subtask_01_15.txt
test_16 subtask_01_16.txt
test_17 subtask_01_17.txt
test_18 subtask_01_18.txt
test_19 subtask_01_19.txt
test_20 subtask_01_20.txt
test_21 subtask_01_21.txt
test_22 subtask_01_22.txt
test_23 subtask_01_23.txt
test_24 subtask_01_24.txt
test_25 subtask_01_25.txt
test_26 subtask_01_26.txt
test_27 subtask_01_27.txt
test_28 subtask_01_28.txt
test_29 subtask_01_29.txt
test_30 subtask_01_30.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 2 ms 640 KB
subtask_01_02.txt AC 2 ms 640 KB
subtask_01_03.txt AC 2 ms 640 KB
subtask_01_04.txt AC 2 ms 640 KB
subtask_01_05.txt AC 2 ms 640 KB
subtask_01_06.txt AC 2 ms 640 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 640 KB
subtask_01_10.txt AC 2 ms 640 KB
subtask_01_11.txt AC 2 ms 640 KB
subtask_01_12.txt AC 2 ms 640 KB
subtask_01_13.txt AC 2 ms 640 KB
subtask_01_14.txt AC 2 ms 640 KB
subtask_01_15.txt AC 2 ms 640 KB
subtask_01_16.txt AC 2 ms 640 KB
subtask_01_17.txt AC 2 ms 640 KB
subtask_01_18.txt AC 2 ms 640 KB
subtask_01_19.txt AC 2 ms 640 KB
subtask_01_20.txt AC 2 ms 640 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 640 KB
subtask_01_24.txt AC 2 ms 640 KB
subtask_01_25.txt AC 2 ms 640 KB
subtask_01_26.txt AC 2 ms 640 KB
subtask_01_27.txt AC 2 ms 512 KB
subtask_01_28.txt AC 2 ms 640 KB
subtask_01_29.txt AC 2 ms 640 KB
subtask_01_30.txt AC 2 ms 640 KB