結果

問題 No.1888 Odd Insertion
ユーザー 👑 ygussanyygussany
提出日時 2022-03-06 17:45:50
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,634 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 32,304 KB
実行使用メモリ 28,420 KB
最終ジャッジ日時 2023-09-28 09:09:10
合計ジャッジ時間 25,657 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 23 ms
4,780 KB
testcase_07 AC 24 ms
4,832 KB
testcase_08 AC 81 ms
20,348 KB
testcase_09 AC 77 ms
23,584 KB
testcase_10 AC 80 ms
18,376 KB
testcase_11 AC 78 ms
23,460 KB
testcase_12 AC 81 ms
18,496 KB
testcase_13 AC 80 ms
20,548 KB
testcase_14 AC 78 ms
23,520 KB
testcase_15 AC 81 ms
17,800 KB
testcase_16 AC 100 ms
19,008 KB
testcase_17 AC 82 ms
18,328 KB
testcase_18 AC 109 ms
19,424 KB
testcase_19 AC 95 ms
21,592 KB
testcase_20 AC 114 ms
17,836 KB
testcase_21 AC 100 ms
22,732 KB
testcase_22 AC 110 ms
17,096 KB
testcase_23 AC 105 ms
20,388 KB
testcase_24 AC 108 ms
20,412 KB
testcase_25 AC 105 ms
20,420 KB
testcase_26 AC 77 ms
17,464 KB
testcase_27 AC 75 ms
28,420 KB
testcase_28 AC 85 ms
6,564 KB
testcase_29 AC 49 ms
11,852 KB
testcase_30 AC 1,957 ms
22,772 KB
testcase_31 AC 1,961 ms
28,360 KB
testcase_32 AC 67 ms
17,392 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘recursion’ 内:
main.c:41:56: 警告: 互換性のないポインタ型から 5 番目の ‘recursion’ の引数に渡しています [-Wincompatible-pointer-types]
   41 |                 if (recursion(N, l + 1, P_inv, BIT, ans[1]) != 0) return 1;
      |                                                        ^
      |                                                        |
      |                                                        int *
main.c:27:57: 備考: expected ‘int (*)[2]’ but argument is of type ‘int *’
   27 | int recursion(int N, int l, int P_inv[], int BIT[], int ans[][2])
      |                                                     ~~~~^~~~~~~~
main.c:60:72: 警告: 互換性のないポインタ型から 5 番目の ‘recursion’ の引数に渡しています [-Wincompatible-pointer-types]
   60 |                                 if (recursion(N, i + 1, P_inv, BIT, ans[i-l+1]) != 0) return 1;
      |                                                                        ^
      |                                                                        |
      |                                                                        int *
main.c:27:57: 備考: expected ‘int (*)[2]’ but argument is of type ‘int *’
   27 | int recursion(int N, int l, int P_inv[], int BIT[], int ans[][2])
      |                                                     ~~~~^~~~~~~~
main.c:80:72: 警告: 互換性のないポインタ型から 5 番目の ‘recursion’ の引数に渡しています [-Wincompatible-pointer-types]
   80 |                                 if (recursion(N, i + 1, P_inv, BIT, ans[i-l+1]) != 0) return 1;
      |                                                                        ^
      |                                                                        |
      |                                                                        int *
main.c:27:57: 備考: expected ‘int (*)[2]’ but argument 

ソースコード

diff #

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

void add_BIT(int N, int BIT[], int i, int k)
{
	while (i <= N) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

struct timeval t;
double beg, cur;

int memo[200001], r;

int recursion(int N, int l, int P_inv[], int BIT[], int ans[][2])
{
	if (l > N) return 1;
	else if (memo[l] != 0) return 0;
	
	gettimeofday(&t, NULL);
	cur = t.tv_sec + (double)t.tv_usec / 1000000;
	if (cur - beg > 1.95) return 0;
	
	int i, k = sum_BIT(BIT, P_inv[l] - 1);
	if (k % 2 == 0) {
		add_BIT(N, BIT, P_inv[l], 1);
		ans[0][0] = l;
		ans[0][1] = k + 1;
		if (recursion(N, l + 1, P_inv, BIT, ans[1]) != 0) return 1;
		add_BIT(N, BIT, P_inv[l], -1);
	}
	if (P_inv[l] % 2 == 0) {
		for (i = l + 1; i < r; i++) {
        	gettimeofday(&t, NULL);
        	cur = t.tv_sec + (double)t.tv_usec / 1000000;
        	if (cur - beg > 1.95) return 0;
			k = sum_BIT(BIT, P_inv[i] - 1);
			if (k % 2 != 0) break;
			add_BIT(N, BIT, P_inv[i], 1);
			ans[i-l-1][0] = i;
			ans[i-l-1][1] = k + 1;
		
			k = sum_BIT(BIT, P_inv[l] - 1);
			if (k % 2 == 0) {
				add_BIT(N, BIT, P_inv[l], 1);
				ans[i-l][0] = l;
				ans[i-l][1] = k + 1;
				if (recursion(N, i + 1, P_inv, BIT, ans[i-l+1]) != 0) return 1;
				add_BIT(N, BIT, P_inv[l], -1);
			}
		}
	} else {
		for (i = l + 1; i <= N; i++) {
        	gettimeofday(&t, NULL);
        	cur = t.tv_sec + (double)t.tv_usec / 1000000;
        	if (cur - beg > 1.95) return 0;
			k = sum_BIT(BIT, P_inv[i] - 1);
			if (k % 2 != 0) break;
			add_BIT(N, BIT, P_inv[i], 1);
			ans[i-l-1][0] = i;
			ans[i-l-1][1] = k + 1;
		
			k = sum_BIT(BIT, P_inv[l] - 1);
			if (k % 2 == 0) {
				add_BIT(N, BIT, P_inv[l], 1);
				ans[i-l][0] = l;
				ans[i-l][1] = k + 1;
				if (recursion(N, i + 1, P_inv, BIT, ans[i-l+1]) != 0) return 1;
				add_BIT(N, BIT, P_inv[l], -1);
			}
		}
	}
	for (i--; i > l; i--) add_BIT(N, BIT, P_inv[i], -1);
	
	memo[l] = -1;
	while (memo[r] != 0) r--;
	return 0;
}

int solve(int N, int P[], int ans[][2])
{
	static int i, P_inv[200001], BIT[200001];
	for (i = 1, memo[0] = 0; i <= N; i++) {
		P_inv[P[i]] = i;
		BIT[i] = 0;
		memo[i] = 0;
	}
	r = N;
	return recursion(N, 1, P_inv, BIT, ans[1]);
}

int main()
{
	gettimeofday(&t, NULL);
	beg = t.tv_sec + (double)t.tv_usec / 1000000;
	
	int i, N, P[200001], ans[200001][2];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	if (solve(N, P, ans) == 0) printf("No\n");
	else {
		printf("Yes\n");
		for (i = 1; i <= N; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
	}
	fflush(stdout);
	return 0;
}
0