提出 #55829821
ソースコード 拡げる
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#define ll long long
#define V vector<ll>
#define VV vector<V>
#define p push
#define po pop
#define pb push_back
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define CNT(x) __builtin_popcountll(x)
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SUM(x) accumulate(all(x), 0LL)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define brep(i, a, b) for (int i = (a); i > (b); i--)
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// order_of_key(x) -> number of elements strictly smaller than x
// find_by_order(k) -> kth element
const double eps = 1e-9;
const int mod = 1e9 + 7;
const double pi = 3.14159265358979323846264338327950;
const int dx[16] = {1, 0, 0, -1, 1, 1, -1, -1, 2, 2, 1, 1, -1, -1, -2, -2};
const int dy[16] = {0, -1, 1, 0, -1, 1, -1, 1, -1, 1, -2, 2, -2, 2, -1, 1};
#define ff first
#define ld long double
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
void print(ll n) {
cout << n << endl;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll lcd(ll a, ll b) {
return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % mod;
n = n >> 1;
x = (x * x) % mod;
}
return res;
}
void print4(vector<vector<ll>> &v) {
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v[i].size(); j++) {
cout << v[i][j] << " ";
}
cout << endl;
}
}
void print3(vector<ll> &v) {
for (int j = 0; j < v.size(); j++) {
cout << v[j] << " ";
}
cout << endl;
}
void print1(vector<string> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << endl;
}
cout << endl;
}
void input(vector<ll> &v, ll n) {
for (int i = 0; i < n; i++) {
ll y;
cin >> y;
v.pb(y);
}
}
ll rt(string &h) {
ll ans = 0;
for (ll i = 0; i < h.size(); i++) {
ans = ans * 1LL * 10 + (h[i] - '0');
}
return ans;
}
bool ispalindrome(ll n) {
string s1 = to_string(n);
string s2 = to_string(n);
reverse(all(s2));
return s1 == s2;
}
bool contain(string &h) {
for (ll i = 0; i < h.size(); i++) {
if (h[i] == '0') return 1;
}
return 0;
}
bool funct(ll num, V &a) {
if (ispalindrome(num)) {
a.pb(num);
return 1;
}
for (ll i = 2; i * 1LL * i <= num; i++) {
string s1 = to_string(i);
string s2 = to_string(i);
reverse(all(s2));
if (contain(s1)) {
continue;
}
if (num % i == 0) {
ll n = rt(s2);
ll gt = num / i;
if (gt % n == 0) {
a.pb(i);
a.pb(n);
if (funct(gt / n, a)) {
return 1;
}
a.pop_back();
a.pop_back();
}
}
}
return 0;
}
void solve() {
ll n;
cin >> n;
V a;
for (ll i = 2; i * 1LL * i <= n; i++) {
string h = to_string(i);
string g = h;
reverse(all(g));
if (contain(g)) {
continue;
}
if (n % i == 0) {
ll newnum = n / i;
ll fact = rt(g);
V ans;
if ((newnum % fact) == 0) {
ans.pb(i);
ans.pb(fact);
if (funct((newnum / fact), ans)) {
a = ans;
break;
}
}
}
}
if (a.size() == 0) {
cout << "-1" << endl;
return;
} else {
if (a.size() % 2 == 1) {
vector<ll> ans(a.size(), 0);
ll j = 0;
for (ll i = 0; i < a.size() / 2; i++) {
ans[i] = a[j];
ans[a.size() - i - 1] = a[j + 1];
j += 2;
}
ans[a.size() / 2] = a[a.size() - 1];
string h = "";
for (ll i = 0; i < ans.size(); i++) {
h = h + to_string(ans[i]);
h = h + "*";
}
h.pop_back();
cout << h << endl;
} else {
vector<ll> ans(a.size(), 0);
ll j = 0;
for (ll i = 0; i < a.size() / 2; i++) {
ans[i] = a[j];
ans[a.size() - i - 1] = a[j + 1];
j += 2;
}
string h = "";
for (ll i = 0; i < ans.size(); i++) {
h = h + to_string(ans[i]);
h = h + "*";
}
h.pop_back();
cout << h << endl;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Palindromic Expression |
| ユーザ | PRAJJAWAL302050 |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 0 |
| コード長 | 5211 Byte |
| 結果 | WA |
| 実行時間 | 237 ms |
| メモリ | 3612 KiB |
コンパイルエラー
Main.cpp: In function ‘void print4(std::vector<std::vector<long long int> >&)’:
Main.cpp:62:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::vector<long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
62 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp:63:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
63 | for (int j = 0; j < v[i].size(); j++) {
| ~~^~~~~~~~~~~~~
Main.cpp: In function ‘void print3(std::vector<long long int>&)’:
Main.cpp:71:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
71 | for (int j = 0; j < v.size(); j++) {
| ~~^~~~~~~~~~
Main.cpp: In function ‘void print1(std::vector<std::__cxx11::basic_string<char> >&)’:
Main.cpp:78:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
78 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp: In function ‘long long int rt(std::string&)’:
Main.cpp:94:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
94 | for (ll i = 0; i < h.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp: In function ‘bool contain(std::string&)’:
Main.cpp:108:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
108 | for (ll i = 0; i < h.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp: In function ‘void solve()’:
Main.cpp:175:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
175 | for (ll i = 0; i < a.size() / 2; i++) {
| ~~^~~~~~~~~~~~~~
Main.cpp:182:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
182 | for (ll i = 0; i < ans.size(); i++) {
| ~~^~~~~~~~~~~~
Main.cpp:191:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
191 | for (ll i = 0; i < a.size() / 2; i++) {
| ~~^~~~~~~~~~~~~~
Main.cpp:197:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
197 | for (ll i = 0; i < ans.size(); i++) {
| ~~^~~~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 500 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 03_random_3_00.txt, 03_random_3_01.txt, 03_random_3_02.txt, 03_random_3_03.txt, 03_random_3_04.txt, 04_random_4_00.txt, 04_random_4_01.txt, 04_random_4_02.txt, 04_random_4_03.txt, 04_random_4_04.txt, 05_random_5_00.txt, 05_random_5_01.txt, 05_random_5_02.txt, 05_random_5_03.txt, 05_random_5_04.txt, 06_hcn_1_00.txt, 06_hcn_1_01.txt, 06_hcn_1_02.txt, 06_hcn_1_03.txt, 06_hcn_1_04.txt, 06_hcn_1_05.txt, 06_hcn_1_06.txt, 06_hcn_1_07.txt, 06_hcn_1_08.txt, 06_hcn_1_09.txt, 07_hcn_2_00.txt, 07_hcn_2_01.txt, 07_hcn_2_02.txt, 07_hcn_2_03.txt, 07_hcn_2_04.txt, 08_hcn_3_00.txt, 08_hcn_3_01.txt, 08_hcn_3_02.txt, 08_hcn_3_03.txt, 08_hcn_3_04.txt, 08_hcn_3_05.txt, 09_hcn_4_00.txt, 09_hcn_4_01.txt, 09_hcn_4_02.txt, 09_hcn_4_03.txt, 09_hcn_4_04.txt, 10_power_of_2_00.txt, 10_power_of_2_01.txt, 11_corner_00.txt, 11_corner_01.txt, 11_corner_02.txt, 11_corner_03.txt, 11_corner_04.txt, 11_corner_05.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3536 KiB |
| 00_sample_01.txt | AC | 1 ms | 3484 KiB |
| 00_sample_02.txt | AC | 1 ms | 3480 KiB |
| 01_random_1_00.txt | AC | 4 ms | 3332 KiB |
| 01_random_1_01.txt | AC | 11 ms | 3472 KiB |
| 01_random_1_02.txt | AC | 8 ms | 3424 KiB |
| 01_random_1_03.txt | AC | 14 ms | 3484 KiB |
| 01_random_1_04.txt | AC | 26 ms | 3476 KiB |
| 02_random_2_00.txt | AC | 49 ms | 3608 KiB |
| 02_random_2_01.txt | AC | 8 ms | 3444 KiB |
| 02_random_2_02.txt | AC | 3 ms | 3612 KiB |
| 02_random_2_03.txt | AC | 6 ms | 3540 KiB |
| 02_random_2_04.txt | AC | 1 ms | 3480 KiB |
| 03_random_3_00.txt | AC | 1 ms | 3476 KiB |
| 03_random_3_01.txt | AC | 18 ms | 3424 KiB |
| 03_random_3_02.txt | AC | 1 ms | 3408 KiB |
| 03_random_3_03.txt | AC | 1 ms | 3424 KiB |
| 03_random_3_04.txt | AC | 11 ms | 3420 KiB |
| 04_random_4_00.txt | AC | 1 ms | 3380 KiB |
| 04_random_4_01.txt | AC | 9 ms | 3536 KiB |
| 04_random_4_02.txt | AC | 10 ms | 3492 KiB |
| 04_random_4_03.txt | AC | 51 ms | 3444 KiB |
| 04_random_4_04.txt | AC | 5 ms | 3516 KiB |
| 05_random_5_00.txt | WA | 11 ms | 3420 KiB |
| 05_random_5_01.txt | WA | 21 ms | 3328 KiB |
| 05_random_5_02.txt | WA | 5 ms | 3480 KiB |
| 05_random_5_03.txt | WA | 6 ms | 3532 KiB |
| 05_random_5_04.txt | WA | 7 ms | 3480 KiB |
| 06_hcn_1_00.txt | AC | 4 ms | 3472 KiB |
| 06_hcn_1_01.txt | AC | 4 ms | 3392 KiB |
| 06_hcn_1_02.txt | AC | 8 ms | 3352 KiB |
| 06_hcn_1_03.txt | AC | 21 ms | 3540 KiB |
| 06_hcn_1_04.txt | AC | 40 ms | 3480 KiB |
| 06_hcn_1_05.txt | AC | 3 ms | 3424 KiB |
| 06_hcn_1_06.txt | AC | 31 ms | 3536 KiB |
| 06_hcn_1_07.txt | AC | 4 ms | 3488 KiB |
| 06_hcn_1_08.txt | AC | 22 ms | 3532 KiB |
| 06_hcn_1_09.txt | AC | 40 ms | 3392 KiB |
| 07_hcn_2_00.txt | AC | 1 ms | 3480 KiB |
| 07_hcn_2_01.txt | AC | 1 ms | 3452 KiB |
| 07_hcn_2_02.txt | AC | 1 ms | 3528 KiB |
| 07_hcn_2_03.txt | AC | 1 ms | 3468 KiB |
| 07_hcn_2_04.txt | WA | 1 ms | 3444 KiB |
| 08_hcn_3_00.txt | AC | 116 ms | 3336 KiB |
| 08_hcn_3_01.txt | AC | 133 ms | 3424 KiB |
| 08_hcn_3_02.txt | AC | 145 ms | 3404 KiB |
| 08_hcn_3_03.txt | AC | 237 ms | 3612 KiB |
| 08_hcn_3_04.txt | AC | 158 ms | 3412 KiB |
| 08_hcn_3_05.txt | AC | 166 ms | 3612 KiB |
| 09_hcn_4_00.txt | AC | 62 ms | 3488 KiB |
| 09_hcn_4_01.txt | AC | 25 ms | 3332 KiB |
| 09_hcn_4_02.txt | AC | 53 ms | 3448 KiB |
| 09_hcn_4_03.txt | AC | 1 ms | 3488 KiB |
| 09_hcn_4_04.txt | AC | 79 ms | 3484 KiB |
| 10_power_of_2_00.txt | AC | 1 ms | 3448 KiB |
| 10_power_of_2_01.txt | AC | 1 ms | 3428 KiB |
| 11_corner_00.txt | WA | 1 ms | 3468 KiB |
| 11_corner_01.txt | WA | 1 ms | 3408 KiB |
| 11_corner_02.txt | AC | 1 ms | 3440 KiB |
| 11_corner_03.txt | AC | 1 ms | 3540 KiB |
| 11_corner_04.txt | AC | 1 ms | 3412 KiB |
| 11_corner_05.txt | AC | 1 ms | 3384 KiB |