結果

問題 No.1711 Divide LCM
ユーザー ygussanyygussany
提出日時 2021-10-15 23:24:13
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 3,833 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 35,072 KB
実行使用メモリ 20,968 KB
最終ジャッジ日時 2024-09-17 18:26:24
合計ジャッジ時間 191,841 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,991 ms
10,112 KB
testcase_01 AC 3,990 ms
10,108 KB
testcase_02 AC 3,991 ms
10,108 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3,995 ms
14,072 KB
testcase_19 AC 3,997 ms
15,980 KB
testcase_20 AC 3,996 ms
14,068 KB
testcase_21 TLE -
testcase_22 AC 3,993 ms
16,872 KB
testcase_23 AC 3,993 ms
17,112 KB
testcase_24 AC 3,996 ms
17,476 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 3,998 ms
16,068 KB
testcase_28 WA -
testcase_29 AC 3,991 ms
10,112 KB
testcase_30 AC 3,998 ms
18,024 KB
testcase_31 AC 3,991 ms
12,276 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 3,990 ms
9,980 KB
testcase_41 AC 3,991 ms
9,984 KB
testcase_42 AC 3,991 ms
10,104 KB
testcase_43 AC 3,991 ms
9,980 KB
testcase_44 AC 3,990 ms
10,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'shuffle_permutation':
main.c:58:28: warning: 'return' with a value, in function returning void
   58 |         if (N == 1) return 0;
      |                            ^
main.c:56:6: note: declared here
   56 | void shuffle_permutation(int N, int p[], int K)
      |      ^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define MT_N 624
#define MT_M 397
#define MT_MATRIX_A 0x9908b0dfUL
#define MT_UPPER_MASK 0x80000000UL
#define MT_LOWER_MASK 0x7fffffffUL

static unsigned int mt[MT_N];
static int mti = MT_N + 1;

void init_genrand(unsigned int s)
{
    mt[0] = s & 0xffffffffUL;
    for (mti = 1; mti < MT_N; mti++) {
        mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 
        mt[mti] &= 0xffffffffUL;
    }
}

unsigned int genrand()
{
    unsigned int y;
    static unsigned int mag01[2] = {0x0UL, MT_MATRIX_A};

    if (mti >= MT_N) {
        int kk;
        if (mti == MT_N + 1) init_genrand(5489UL);
		
        for (kk = 0; kk < MT_N - MT_M; kk++) {
            y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK);
            mt[kk] = mt[kk+MT_M] ^ (y >> 1) ^ mag01[y&0x1UL];
        }
        for (; kk < MT_N - 1; kk++) {
            y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK);
            mt[kk] = mt[kk+(MT_M-MT_N)] ^ (y >> 1) ^ mag01[y&0x1UL];
        }
        y = (mt[MT_N-1] & MT_UPPER_MASK) | (mt[0] & MT_LOWER_MASK);
        mt[MT_N-1] = mt[MT_M-1] ^ (y >> 1) ^ mag01[y&0x1UL];

        mti = 0;
    }
  
    y = mt[mti++];

    y ^= (y >> 11);
    y ^= (y << 7) & 0x9d2c5680UL;
    y ^= (y << 15) & 0xefc60000UL;
    y ^= (y >> 18);

    return y;
}

void shuffle_permutation(int N, int p[], int K)
{
	if (N == 1) return 0;
	
	int i, j, k;
	for (k = 0; k < K; k++) {
		do {
			i = genrand() % N + 1;
			j = genrand() % N + 1;
		} while (i == j);
		p[i] ^= p[j];
		p[j] ^= p[i];
		p[i] ^= p[j];
	}
}

void chmax(int* a, int b)
{
	if (*a < b) *a = b;
}

typedef struct Edge {
	struct Edge *next;
	int v;
} edge;

int main()
{
	init_genrand(46);
	struct timeval t;
	double beg, cur;
	gettimeofday(&t, NULL);
	beg = t.tv_sec + (double)t.tv_usec / 1000000;
	
	int i, j, k = 0, l, N, A[100001], prime[100001], max[100001], flag[1000001] = {}, m[100001], *p[100001], *e[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(m[i]));
		p[i] = (int*)malloc(sizeof(int) * (m[i] + 1));
		e[i] = (int*)malloc(sizeof(int) * (m[i] + 1));
		for (j = 1, A[i] = 1; j <= m[i]; j++) {
			scanf("%d %d", &(p[i][j]), &(e[i][j]));
			for (l = 0; l < e[i][j]; l++) A[i] *= p[i][j];
			if (flag[p[i][j]] == 0) {
				prime[++k] = p[i][j];
				max[k] = e[i][j];
				flag[p[i][j]] = k;
			} else chmax(&(max[flag[p[i][j]]]), e[i][j]);
		}
	}
	
	edge *adj[100001] = {}, ed[1000001], *po;
	for (i = 1, l = 0; i <= N; i++) {
		for (j = 1; j <= m[i]; j++) {
			if (e[i][j] != max[flag[p[i][j]]]) continue;
			ed[l].v = i;
			ed[l].next = adj[flag[p[i][j]]];
			adj[flag[p[i][j]]] = &(ed[l++]);
		}
	}
	
	int q[100001], live[100001], ans = k + 1, q_ans[100001];
	for (i = 1; i <= k; i++) q[i] = i;
	shuffle_permutation(k, q, k * 10);
	while (1) {
		gettimeofday(&t, NULL);
		cur = t.tv_sec + (double)t.tv_usec / 1000000;
		if (cur - beg > 3.99) break;
		
		for (i = 1; i <= N; i++) live[i] = 1;
		for (i = 1; i <= k; i++) {
			j = q[i];
			for (po = adj[j], live[0] = 0; po != NULL; po = po->next) {
				if (live[po->v] == i) {
					live[po->v]++;
					live[0] = 1;
				}
			}
			if (live[0] == 0) break;
		}
		if (ans > i) {
			ans = i;
			for (i = 1; i <= k; i++) q_ans[i] = q[i];
		}
		
		shuffle_permutation(k, q, 1000 + genrand() % 2);
	}
	
	if (ans == k + 1) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	
	int num[100001] = {};
	printf("%d\n", ans);
	for (i = 1; i <= N; i++) live[i] = 1;
	for (i = 1; i <= ans; i++) {
		j = q[i];
		for (po = adj[j]; po != NULL; po = po->next) if (live[po->v] == i) live[po->v]++;
	}
	for (i = 1; i <= N; i++) num[live[i]]++;
	for (i = 1; i <= ans; i++) {
		printf("%d", num[i]);
		for (j = 1; j <= N; j++) if (live[j] == i) printf(" %d", A[j]);
		printf("\n");
	}
	fflush(stdout);
	return 0;
}
0