結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー magurofly
提出日時 2026-04-17 21:10:24
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 798 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 537 ms
コンパイル使用メモリ 8,832 KB
実行使用メモリ 34,976 KB
平均クエリ数 11.44
最終ジャッジ日時 2026-04-17 21:10:45
合計ジャッジ時間 20,769 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18 WA * 54
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

STDOUT.sync = true
N = gets.to_i

products = []
N.times do |i|
	a, b = [i, (i + 1) % N].minmax
	puts "? #{a} #{b}"
	x = gets.to_i
	products << x
end

digit_candidates = Array.new(N) { [true] * 10 }
digit_candidates[-1][0] = false
N.times do
	N.times do |i|
		10.times do |a|
			if (0 ... 10).all? { |b| products[i] != a * b }
				digit_candidates[i][a] = false
			end
		end
		if digit_candidates[i].count(true) == 1
			x = (0 ... 10).find { |x| digit_candidates[i][x] }
			if x != 0
				ys = [false] * 10
				ys[products[i] / x] = true
				digit_candidates[(i + 1) % N] = ys
			end
		end
	end
end

if digit_candidates.all? { |c| c.count(true) == 1 }
	ans = ""
	(0 ... N).reverse_each do |i|
		x = (0 ... 10).find { |x| digit_candidates[i][x] }
		ans << x
	end
	puts "! #{ans}"
else
	puts "! -1"
end
0