結果
| 問題 |
No.2198 Concon Substrings (COuNt-CONstruct Version)
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2023-01-20 23:15:28 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 2,515 bytes |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 32,296 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 11:17:19 |
| 合計ジャッジ時間 | 4,903 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 104 |
ソースコード
#include <stdio.h>
long long gcd (long long a, long long b, long long *x, long long *y) {
long long ans = 0LL;
if (b <= 0LL) {
*x = 1LL;
*y = 0LL;
return a;
}
ans = gcd(b, a%b, y, x);
*y -= (a/b)*(*x);
return ans;
}
int main () {
long long m = 0LL;
int res = 0;
long long c = 1LL;
long long o = 1LL;
long long n = 1LL;
long long diff = 0LL;
long long d = 0LL;
long long x = 0LL;
long long y = 0LL;
char ans[60001] = "";
int idx = 0;
long long tmp_c = 0LL;
long long tmp_o = 0LL;
long long tmp_n = 0LL;
res = scanf("%lld", &m);
if (m == 0LL) {
printf("a\n");
return 0;
}
while (c*c*c <= m) {
if (m%c == 0LL) {
long long tmp = m/c;
o = 1LL;
while (o*o <= tmp) {
if (tmp%o == 0LL && c+o+tmp/o <= 60000LL) {
n = tmp/o;
for (int i = 0; i < (int)c; i++) {
ans[idx] = 'c';
idx++;
}
for (int i = 0; i < (int)o; i++) {
ans[idx] = 'o';
idx++;
}
for (int i = 0; i < (int)n; i++) {
ans[idx] = 'n';
idx++;
}
ans[idx] = '\0';
printf("%s\n", ans);
return 0;
}
o += 1LL;
}
}
c += 1LL;
}
o = c;
n = c+1LL;
while (c*o*n-m < c*n-c-n) {
o += 1LL;
}
diff = c*o*n-m;
d = gcd(c, n, &x, &y);
x *= diff/d;
y *= diff/d;
if (x < 0LL) {
long long mul = 1LL+(-x-1LL)/n;
x += mul*n;
y -= mul*c;
}
if (y < 0LL) {
long long mul = 1LL+(-y-1LL)/c;
x -= mul*n;
y += mul*c;
}
tmp_c = c;
tmp_o = o;
tmp_n = n;
//printf("%lld %lld %lld %lld %lld\n", c, o, n, x, y);
for (int i = 0; i < (int)(y/c); i++) {
ans[idx] = 'o';
idx++;
tmp_o -= 1LL;
}
while (tmp_c > y%c) {
ans[idx] = 'c';
idx++;
tmp_c -= 1LL;
}
if (tmp_c > 0LL) {
ans[idx] = 'o';
idx++;
tmp_o--;
}
while (tmp_c > 0LL) {
ans[idx] = 'c';
idx++;
tmp_c -= 1LL;
}
while (tmp_o > 1LL+x/n) {
ans[idx] = 'o';
idx++;
tmp_o -= 1LL;
}
for (int i = 0; i < (int)(x%n); i++) {
ans[idx] = 'n';
idx++;
tmp_n -= 1LL;
}
ans[idx] = 'o';
idx++;
tmp_o--;
while (tmp_n > 0LL) {
ans[idx] = 'n';
idx++;
tmp_n -= 1LL;
}
for (int i = 0; i < (int)(x/n); i++) {
ans[idx] = 'o';
idx++;
tmp_o -= 1LL;
}
ans[idx] = '\0';
printf("%s\n", ans);
return 0;
}
chro_96