Submission #40006135
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
void solve(){
vector<string> ans(100, "");
for (int r = 1; r < 10; r++)
{
modint::set_mod(9 * r);
vector<vector<bool>> vis(9*r, vector<bool>(1024));
vector<vector<string>> st(9*r, vector<string>(1024));
vis[0][0] = true;
queue<tuple<modint, int, modint, int, int>> q;
q.emplace(0, 0, 0, 0, 0);
while(not q.empty())
{
auto [x, b, prx, prb, last] = q.front();
q.pop();
vector<int> tmp;
for (int i = 0; i < 10; i++)
{
if((b >> i) & 1) tmp.push_back(i);
}
if(not tmp.empty())
{
int d = 0;
for (int i = 1; i < tmp.size(); i++)
{
d = gcd(d, tmp[i] - tmp[i-1]);
}
st[x.val()][b] = st[prx.val()][prb];
st[x.val()][b].push_back(char('0' + last));
if(d == r) ans[gcd(9 * r, x.val())] = st[x.val()][b];
}
for (int i = 0; i < 10; i++)
{
if(b == 0 and i == 0) continue;
modint nx = x * 10 + i;
int nb = b | (1 << i);
if(vis[nx.val()][nb]) continue;
vis[nx.val()][nb] = true;
q.emplace(nx, nb, x, b, i);
}
}
}
int t;
cin >> t;
for (int id = 0; id < t; id++)
{
string s;
ll k;
cin >> s;
k = atoll(s.data());
char c = s[0];
bool f = true;
for(auto t : s) if(t != c) f = false;
if(f){
cout << s << '\n';
continue;
}
if(k >= 100 or ans[k] == ""){
cout << -1 << '\n';
continue;
}
cout << ans[k] << '\n';
}
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
}
Submission Info
Submission Time
2023-03-25 14:14:08+0900
Task
A - Shuffle and GCD
User
Motsu_xe
Language
C++ (GCC 9.2.1)
Score
100
Code Size
2318 Byte
Status
AC
Exec Time
153 ms
Memory
6736 KiB
Compile Error
./Main.cpp: In function ‘void solve()’:
./Main.cpp:32:35: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
32 | for (int i = 1; i < tmp.size(); i++)
| ~~^~~~~~~~~~~~
Judge Result
Set Name
sample
All
Score / Max Score
0 / 0
100 / 100
Status
Set Name
Test Cases
sample
00_sample_01
All
00_sample_01, 01_test_01, 01_test_02, 01_test_03
Case Name
Status
Exec Time
Memory
00_sample_01
AC
153 ms
6644 KiB
01_test_01
AC
152 ms
6672 KiB
01_test_02
AC
152 ms
6656 KiB
01_test_03
AC
152 ms
6736 KiB