結果
| 問題 | 
                            No.3109 Swap members
                             | 
                    
| コンテスト | |
| ユーザー | 
                             pengin_2000
                         | 
                    
| 提出日時 | 2025-04-18 20:46:16 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 114 ms / 2,000 ms | 
| コード長 | 1,623 bytes | 
| コンパイル時間 | 1,473 ms | 
| コンパイル使用メモリ | 26,240 KB | 
| 実行使用メモリ | 14,912 KB | 
| 最終ジャッジ日時 | 2025-04-18 20:46:22 | 
| 合計ジャッジ時間 | 5,618 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 52 | 
コンパイルメッセージ
main.c: In function ‘main’:
main.c:77:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   77 |         scanf("%d %d", &n, &k);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:80:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |                 scanf("%s", s[i]);
      |                 ^~~~~~~~~~~~~~~~~
main.c:82:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |                 scanf("%s", t[i]);
      |                 ^~~~~~~~~~~~~~~~~
            
            ソースコード
#include<stdio.h>
int strcmp(char s[], char t[])
{
	int i;
	for (i = 0;; i++)
	{
		if (s[i] == '\0' && t[i] == '\0')
			return 0;
		if (t[i] == '\0')
			return 1;
		if (s[i] == '\0')
			return -1;
		if (s[i] > t[i])
			return 1;
		if (s[i] < t[i])
			return -1;
	}
}
char s[100005][64], t[100005][64];
int h[100005], l;
int comp_h(int a, int b)
{
	return strcmp(s[h[a]], s[h[b]]);
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(int ne)
{
	h[l] = ne;
	int p = l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	swap_h(0, --l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int c[100005];
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i;
	for (i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (i = 0; i < n; i++)
		scanf("%s", t[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(i);
	for (i = 0; i < n; i++)
		c[i] = pop();
	int min, mid, max;
	for (i = 0; i < n; i++)
	{
		min = -1;
		max = n;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (strcmp(s[c[mid]], t[i]) < 0)
				min = mid;
			else
				max = mid;
		}
		if (i % k != c[max] % k)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}
            
            
            
        
            
pengin_2000