結果

問題 No.202 1円玉投げ
ユーザー kimiyuki
提出日時 2017-03-14 22:26:46
言語 C++14
(gcc 7.1.0)
結果
AC  
実行時間 2510 ms
コード長 2053 Byte
コンパイル時間 1047 ms
使用メモリ 2480 KB

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
challenge01.txt AC 2446 ms
2480 KB
sample01.txt AC 3 ms
1312 KB
sample02.txt AC 3 ms
1320 KB
sample03.txt AC 2 ms
1312 KB
system_test1.txt AC 12 ms
1384 KB
system_test2.txt AC 1705 ms
2288 KB
system_test3.txt AC 2119 ms
2400 KB
system_test4.txt AC 2223 ms
2412 KB
system_test5.txt AC 704 ms
1928 KB
system_test6.txt AC 126 ms
1572 KB
system_test7.txt AC 460 ms
1820 KB
system_test8.txt AC 501 ms
1832 KB
system_test9.txt AC 153 ms
1600 KB
system_test10.txt AC 17 ms
1396 KB
system_test11.txt AC 637 ms
1904 KB
system_test12.txt AC 2455 ms
2476 KB
system_test13.txt AC 2462 ms
2480 KB
system_test14.txt AC 2480 ms
2480 KB
system_test15.txt AC 558 ms
1872 KB
system_test16.txt AC 1370 ms
2188 KB
system_test17.txt AC 555 ms
1864 KB
test01-1000-align-x0.txt AC 3 ms
1336 KB
test02-1000-align-x1.txt AC 4 ms
1328 KB
test03-1000-align-x2.txt AC 3 ms
1332 KB
test04-1000-align-x3.txt AC 4 ms
1328 KB
test05-1000-align-y0.txt AC 3 ms
1328 KB
test06-1000-align-y1.txt AC 4 ms
1324 KB
test07-1000-align-y2.txt AC 3 ms
1328 KB
test08-1000-align-y3.txt AC 2 ms
1324 KB
test09-1000-align-d0.txt AC 3 ms
1328 KB
test10-1000-one01.txt AC 3 ms
1324 KB
test11-1000-rand01.txt AC 3 ms
1328 KB
test12-1000-rand02.txt AC 3 ms
1332 KB
test13-1000-honeycomb01.txt AC 4 ms
1332 KB
test14-100000-align01.txt AC 2510 ms
2480 KB
test15-100000-align02.txt AC 2475 ms
2476 KB
test16-100000-rand01.txt AC 2472 ms
2476 KB
test17-100000-align03.txt AC 2493 ms
2480 KB
test18-contact01.txt AC 4 ms
1316 KB
test19-contact02.txt AC 3 ms
1316 KB
テストケース一括ダウンロード

ソースコード

diff #
#pragma GCC optimize "O3"
#pragma GCC target "tune=native"
#pragma GCC target "avx"
#include <cstdio>
#include <algorithm>
#include <immintrin.h>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
template <class T> inline T sq(T x) { return x*x; }
constexpr int max_n = 100000;
constexpr int r = 10;
__attribute__((aligned(32))) int32_t x[max_n];
__attribute__((aligned(32))) int32_t y[max_n];
__attribute__((aligned(32))) int32_t z[max_n]; // is_removed
int main() {
    int n; scanf("%d", &n);
    repeat (i,n) scanf("%d%d", &x[i], &y[i]);
    int i = 0;
    for (; i+3 < n; i += 4) {
        const __m128i xi = _mm_load_si128((__m128i *)(x + i));
        const __m128i yi = _mm_load_si128((__m128i *)(y + i));
        __m128i zi = _mm_setzero_si128();
        repeat (j,i) {
            __m128i xj = _mm_set1_epi32(x[j]);
            __m128i yj = _mm_set1_epi32(y[j]);
            __m128i zj = _mm_set1_epi32(not z[j]);
            xj = _mm_sub_epi32(xj, xi);
            yj = _mm_sub_epi32(yj, yi);
            xj = _mm_mullo_epi32(xj, xj);
            yj = _mm_mullo_epi32(yj, yj);
            const __m128i d = _mm_add_epi32(xj, yj);
            const __m128i e = _mm_set1_epi32(sq(r + r));
            __m128i cmp = _mm_cmplt_epi32(d, e);
            zi = _mm_add_epi32(zi, _mm_mullo_epi32(cmp, zj));
        }
        _mm_store_si128((__m128i *)(z + i), zi);
        repeat (di, 4) {
            if (z[i+di]) {
                z[i+di] = 1;
            } else {
                repeat (dj, di) {
                    if (not z[i+dj] and sq(x[i+dj] - x[i+di]) + sq(y[i+dj] - y[i+di]) < sq(r + r) ) {
                        z[i+di] = 1;
                        break;
                    }
                }
            }
        }
    }
    for (; i < n; ++ i) {
        repeat (j,i) {
            if (not z[j] and sq(x[j] - x[i]) + sq(y[j] - y[i]) < sq(r + r) ) {
                z[i] = 1;
                break;
            }
        }
    }
    int cnt = count(z, z + n, 0);
    printf("%d\n", cnt);
    return 0;
}
0