結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー daiota
提出日時 2026-04-19 05:39:18
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,383 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,919 ms
コンパイル使用メモリ 214,936 KB
実行使用メモリ 30,320 KB
平均クエリ数 10.89
最終ジャッジ日時 2026-04-19 05:39:35
合計ジャッジ時間 12,979 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
















int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	ll i,j,k;



	ll N;
	cin >> N;


	vector<ll> x(N,-1),a(N,-1),v;
	for(i=N-2;i>=0;i--){

		cout << "? " << i << ' ' << N-1 << endl;
		cout.flush();

		ll p;
		cin >> p;

		x[i]=p;
		if(p!=0) v.push_back(i);

	}

	ll n=v.size();
	if(n==0){
		cout << "! " << -1 << endl;
		cout.flush();
	}

	else if(n==1){
		j=v[0];
		if(x[j]==1){
			a[j]=1;
			a[N-1]=1;
		}
		else if(x[j]==25){
			a[j]=5;
			a[N-1]=5;
		}
		else if(x[j]==49){
			a[j]=7;
			a[N-1]=7;
		}
		else if(x[j]==64){
			a[j]=8;
			a[N-1]=8;
		}
		else if(x[j]==81){
			a[j]=9;
			a[N-1]=9;
		}
		else{
			cout << "! " << -1 << endl;
			cout.flush();
			return 0;
		}


		for(i=N-1;i>=0;i--){
			if(a[i]!=-1) continue;
			a[i]=x[i]/a[N-1];
		}

		cout << "! ";
		for(i=N-1;i>=0;i--) cout << a[i];
		cout << endl;
		cout.flush();


	}
	else{

		j=v[0];
		k=v[1];

		cout << "? " << k << ' ' << j << endl;
		cout.flush();

		ll r;
		cin >> r;

		a[N-1]=(ll)sqrt(1.0*x[j]*x[k]/r);
		a[j]=x[j]/a[N-1];
		a[k]=x[k]/a[N-1];


		for(i=N-1;i>=0;i--){
			if(a[i]!=-1) continue;
			a[i]=x[i]/a[N-1];
		}

		cout << "! ";
		for(i=N-1;i>=0;i--) cout << a[i];
		cout << endl;
		cout.flush();
	}









	return 0;

}
0