結果
| 問題 |
No.2030 Googol Strings
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-05 22:35:07 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 2,000 ms |
| コード長 | 1,687 bytes |
| コンパイル時間 | 1,811 ms |
| コンパイル使用メモリ | 105,600 KB |
| 実行使用メモリ | 29,696 KB |
| 最終ジャッジ日時 | 2024-09-15 19:51:31 |
| 合計ジャッジ時間 | 3,918 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static void Main()
{
var t = NN;
var res = new char[t];
for (var u = 0; u < t; ++u)
{
var x = ReadLine();
var y = ReadLine();
res[u] = Compare(x, y);
}
WriteLine(string.Join("\n", res));
}
static char Compare(string x, string y)
{
if (x[0] > y[0]) return 'X';
if (x[0] < y[0]) return 'Y';
if (IsRepeat(x, y))
{
if (x.Length > y.Length) return 'X';
else return 'Y';
}
var pos = 1;
while (true)
{
var xi = pos % x.Length;
var yi = pos % y.Length;
if (xi == 0 && yi == 0) break;
if (x[xi] > y[yi]) return 'X';
if (x[xi] < y[yi]) return 'Y';
++pos;
}
return ' ';
}
static bool IsRepeat(string x, string y)
{
var gcd = GCD(x.Length, y.Length);
var glist = x.Take(gcd).ToArray();
for (var i = gcd; i < x.Length; ++i)
{
if (x[i] != glist[i % gcd]) return false;
}
for (var i = 0; i < y.Length; ++i)
{
if (y[i] != glist[i % gcd]) return false;
}
return true;
}
static int GCD(int a, int b)
{
if (a < b) return GCD(b, a);
if (a % b == 0) return b;
return GCD(b, a % b);
}
}