結果

問題 No.989 N×Mマス計算(K以上)
ユーザー bal4ubal4u
提出日時 2020-02-16 06:39:18
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,886 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 30,628 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-28 19:33:06
合計ジャッジ時間 1,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:10:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:11:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:22:17: 備考: in expansion of macro ‘pc’
   22 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yuki 989 N×Mマス計算(K以上)
// 2020.2.16 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(ll n) { // 非負整数の表示(出力)
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
    pc('\n');
}

void Usort(int *a, int n) {
	int i, k;
#define B 8
#define BMSK 255 // (1<<8)-1
	int t1[1 << B], t2[1 << B];

	int *tmp = malloc(n * sizeof(int));
	for (k = 0; k < 8; ++k) {  // for 64ビット
		memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2));
		for (i = 0; i < n; ++i)	t1[(a[i] >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t1[i+1] += t1[i];
		i = n; while (i--) tmp[--t1[(a[i] >> k*B) & BMSK]] = a[i];
		k++;
		for (i = 0; i < n; ++i) t2[(tmp[i] >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t2[i+1] += t2[i];
		i = n; while (i--) a[--t2[(tmp[i] >> k*B) & BMSK]] = tmp[i];
	}
	free(tmp);
// for (i = 0; i < n; ++i) printf("[%d] %lld\n", i, a[i]);
#undef B
}

int B[100005]; int M;

// バイナリサーチ。見つからなければ、一つ大きい要素を返す。つまり、 >= x
int bs(int x) {
	int m, l = 0, r = M;

    while (l < r) {
        m = (l+r) >> 1;
        if (B[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int main()
{
    int i, j, N, K, op, A;
    ll ans;

    N = in(), M = in(), K = in();
    op = (gc() == '+'), gc();
    for (i = 0; i < M; ++i) B[i] = in();
    Usort(B, M);

    ans = 0;
    for (j = 0; j < N; ++j) {
        A = in();
        if (op) ans += M - bs(K-A);
        else if (K % A)   ans += M - bs(K/A+1);
        else              ans += M - bs(K/A);
    }
    out(ans);
    return 0;
}
0