結果
| 問題 | No.3501 Digit Products 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 14:36:14 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,434 bytes |
| 記録 | |
| コンパイル時間 | 4,170 ms |
| コンパイル使用メモリ | 374,960 KB |
| 実行使用メモリ | 30,076 KB |
| 平均クエリ数 | 10.89 |
| 最終ジャッジ日時 | 2026-04-18 14:36:33 |
| 合計ジャッジ時間 | 10,812 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 71 WA * 1 |
ソースコード
// Compile: g++ -std=c++20 -O2 -Wall -I$HOME/ctf/tools/ac-library -DLOCAL -o sol sol.cpp
// Or: make sol (uses Makefile in this dir)
// Run: ./sol < in.txt
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define rep2(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((ll)(x).size())
template<class T> bool chmin(T&a,const T&b){if(b<a){a=b;return true;}return false;}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
#ifdef LOCAL
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#else
#define dbg(x)
#endif
using mint = modint998244353;
// using mint = modint1000000007;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> prd(n - 1);
for (int i = 1; i < n; i++) {
int b = n - 1;
int a = n - 1 - i;
cout << "? " << a << " " << b << endl;
int p;
cin >> p;
prd[i - 1] = p;
}
if(n==2) {
if(prd[0] == 1) cout << "! 11" << endl;
else if(prd[0] == 25) cout << "! 25" << endl;
else if(prd[0] == 49) cout << "! 77" << endl;
else if(prd[0] == 64) cout << "! 88" << endl;
else if(prd[0] == 81) cout << "! 99" << endl;
else cout << "! -1" << endl;
return 0;
}
int count_not_zero = 0;
int last_prd = 0;
vector<int> last(2);
for (int i = 0; i < n - 1; i++) {
if(prd[i] != 0) {
last[count_not_zero] = n - 2 - i;
last_prd = prd[i];
count_not_zero++;
if (count_not_zero >= 2) break;
}
}
if (count_not_zero >= 2){
cout << "? " << last[1] << " " << last[0] << endl;
int p;
cin >> p;
for (int first_digit = 1; first_digit <= 9; first_digit++){
bool is_ok = true;
rep(j, sz(prd)) {
if (prd[j] % first_digit != 0) is_ok = false;
}
if(is_ok) {
int a_digit = prd[n-2-last[1]] / first_digit;
int b_digit = prd[n-2-last[0]] / first_digit;
if( p == a_digit*b_digit) {
cout << "! " << first_digit;
rep(d, n-1) {
cout << prd[d] / first_digit;
}
cout << endl;
return 0;
}
}
}
}else{
if (count_not_zero==0){
cout << "! -1" << endl;
return 0;
}else{
// 101,505,707,808,909は解けるはず・・・・
if(last_prd==1 ||last_prd==25 ||last_prd==49 ||last_prd==64 ||last_prd==81){
int first_digit = (int)sqrt(last_prd);
cout << "! " << first_digit;
rep(d, n-1) {
if(d == n-2-last[0]) cout << first_digit;
else cout << "0";
}
cout << endl;
return 0;
}else{
cout << "! -1" << endl;
return 0;
}
}
}
return 0;
}