Submission #3910465
Source Code Expand
#if 0
cat <<EOF >mistaken-paste
#endif
// thanks for @rsk0315_h4x
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#define BIG 2000000007
#define VERYBIG 2000000000000007LL
#define MOD 1000000007
#define FOD 998244353
typedef uint64_t ull;
typedef int64_t sll;
#define N_MAX 1000000
#ifdef __cplusplus
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <functional>
#include <array>
using std::queue;
using std::priority_queue;
using std::stack;
using std::tuple;
using std::set;
using std::map;
using std::vector;
using std::greater;
using std::pair;
using std::string;
using std::get;
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> l, pair<T, U> r) {
return pair<T, U>(l.first + r.first, l.second + r.second);
}
#endif
typedef struct {
int32_t a;
int32_t b;
} hw;
typedef struct {
sll a;
sll b;
} hwll;
typedef struct {
sll a;
sll b;
sll c;
} hwllc;
typedef struct {
hwll a;
hwll b;
} linell;
ull n, m;
ull h, w;
ull k;
ull q;
sll va, vb, vc, vd, ve, vf;
ull ua, ub, uc, ud, ue, uf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
char ch, dh;
ull umin (ull x, ull y) {
return (x < y) ? x : y;
}
ull umax (ull x, ull y) {
return (x > y) ? x : y;
}
sll smin (sll x, sll y) {
return (x < y) ? x : y;
}
sll smax (sll x, sll y) {
return (x > y) ? x : y;
}
ull gcd (ull x, ull y) {
if (x < y) {
return gcd(y, x);
} else if (y == 0) {
return x;
} else {
return gcd(y, x % y);
}
}
ull bitpow (ull a, ull x, ull modulo) {
ull result = 1;
while (x) {
if (x & 1) {
result *= a;
result %= modulo;
}
x /= 2;
a = (a * a) % modulo;
}
return result;
}
ull divide (ull a, ull b, ull modulo) {
return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}
ull udiff (ull a, ull b) {
if (a >= b) {
return a - b;
} else {
return b - a;
}
}
sll sdiff (sll a, sll b) {
if (a >= b) {
return a - b;
} else {
return b - a;
}
}
int bitcount (ull n) {
int result = 0;
while (n) {
if (n & 1) result++;
n /= 2;
}
return result;
}
#define BEGCMP(NAME) int32_t NAME (const void *left, const void *right)
#define DEFLR(TYPE) TYPE l=*(TYPE*)left,r=*(TYPE*)right
#define CMPRET(L, R) if((L)<(R))return-1;if((L)>(R))return+1
// int32_t pullcomp (const void *left, const void *right) {
// ull l = *(ull*)left;
// ull r = *(ull*)right;
// if (l < r) {
// return -1;
// }
// if (l > r) {
// return +1;
// }
// return 0;
// }
BEGCMP(pullcomp){
DEFLR(ull);
CMPRET(l, r);
return 0;
}
BEGCMP(prevcomp){
DEFLR(ull);
CMPRET(r, l);
return 0;
}
BEGCMP(psllcomp){
DEFLR(sll);
CMPRET(l, r);
return 0;
}
BEGCMP(pcharcomp){
DEFLR(char);
CMPRET(l, r);
return 0;
}
BEGCMP(pdoublecomp){
DEFLR(double);
CMPRET(l, r);
return 0;
}
int32_t pstrcomp (const void *left, const void *right) {
char* l = *(char**)left;
char* r = *(char**)right;
return strcmp(l, r);
}
BEGCMP(phwllABcomp){
DEFLR(hwll);
CMPRET(l.a, r.a);
CMPRET(l.b, r.b);
return 0;
}
BEGCMP(phwllREVcomp){
DEFLR(hwll);
CMPRET(l.b, r.b);
CMPRET(l.a, r.a);
return 0;
}
BEGCMP(ptriplecomp){
DEFLR(hwllc);
CMPRET(l.a, r.a);
CMPRET(l.b, r.b);
CMPRET(l.c, r.c);
return 0;
}
BEGCMP(ptripleREVcomp){
DEFLR(hwllc);
CMPRET(l.b, r.b);
CMPRET(l.a, r.a);
CMPRET(l.c, r.c);
return 0;
}
int32_t pquadcomp (const void *left, const void *right) {
linell l = *(linell*)left;
linell r = *(linell*)right;
sll ac = phwllABcomp(&(l.a), &(r.a));
if (ac) return ac;
sll bc = phwllABcomp(&(l.b), &(r.b));
if (bc) return bc;
return 0;
}
bool isinrange (sll left, sll x, sll right) {
return (left <= x && x <= right);
}
bool isinrange_soft (sll left, sll x, sll right) {
return (left <= x && x <= right) || (left >= x && x >= right);
}
sll a[N_MAX + 5];
// ull a[N_MAX + 5];
// sll a[3001][3001];
sll b[N_MAX + 5];
// ull b[N_MAX + 5];
// sll b[3001][3001];
ull c[N_MAX + 5];
ull d[N_MAX + 5];
sll e[N_MAX];
char s[N_MAX + 1];
// char s[3010][3010];
char t[N_MAX + 1];
// char t[3010][3010];
// char u[N_MAX + 1];
hwll xy[N_MAX + 5];
hwllc tup[N_MAX + 5];
sll table[3005][3005];
// here we go
ull slen[N_MAX];
char *sp[N_MAX];
sll stot[N_MAX];
sll ttos[N_MAX];
ull sest = VERYBIG;
sll itop[N_MAX];
bool iswatched[N_MAX];
ull flow (ull ki, char x) {
ull j;
iswatched[ki] = true;
for (j = 0; j < n; j++) {
if (iswatched[j + n]) continue;
// printf("itop[%lld]: %lld, slen[%lld]: %lld, sp[%lld][%lld]: '%c'\n", j, itop[j], ki, slen[ki], ki, itop[j], x);
if (itop[j] < 0 || itop[j] >= slen[ki] || sp[ki][itop[j]] != x) continue;
iswatched[j + n] = true;
if (ttos[j] < 0) {
stot[ki] = j;
ttos[j] = ki;
return 1;
} else {
if (!iswatched[ttos[j]] && flow(ttos[j], x)) {
stot[ki] = j;
ttos[j] = ki;
return 1;
}
}
}
return 0;
}
bool isok (char x) {
sll i, j, ki;
ull f = 0;
for (i = 0; i < n; i++) {
stot[i] = ttos[i] = -1;
itop[i] = -1;
}
j = 0;
for (i = 0; i < sest + n + 10; i++) {
if (j + n <= i) {
if (ttos[j % n] >= 0) {
stot[ttos[j % n]] = -1;
ttos[j % n] = -1;
f--;
}
j++;
}
itop[i % n] = i;
while (true) {
for (ki = 0; ki < n * 2; ki++) iswatched[ki] = false;
for (ki = 0; ki < n; ki++) {
if (stot[ki] < 0 && !iswatched[ki] && flow(ki, x)) {
f++;
break;
}
}
if (ki == n) break;
}
// if (x > 'd') continue;
// printf("%c/%lld:\n", x, i);
// for (ki = 0; ki < n; ki++) {
// printf("%lld - %lld\n", stot[ki], ttos[ki]);
// }
// puts("");
if (f >= n) return true;
}
return false;
}
ull solve () {
sll i, j, ki, li;
// ull result = 0;
sll result = 0;
double dresult = 0;
// ull maybe = 0;
sll maybe = 0;
// ull sum = 0;
sll sum = 0;
sll item;
ull *dpcell;
char *p = s;
for (i = 0; i < n; i++) {
sp[i] = p;
scanf("%s", sp[i]);
slen[i] = strlen(sp[i]);
sest = umin(sest, slen[i]);
p += slen[i] + 1;
}
for (char c = 'a'; c <= 'z'; c++) {
if (isok(c)) goto success;
}
goto fail;
printf("%lld\n", result);
// printf("%.15lf\n", dresult);
// puts(s);
return 0;
success:
puts("YES");
// puts("Yes");
// printf("%llu\n", result);
// puts("0");
// puts("Yay!");
return 0;
fail:
puts("NO");
// puts("No");
// puts("0");
// puts("-1");
// puts("-1 -1 -1");
// puts("Impossible");
return 1;
}
int32_t main (void) {
int32_t i, j;
int32_t x, y;
// scanf("%llu%llu", &h, &w);
scanf("%llu", &n, &m);
// scanf("%llu%llu", &k, &n, &m);
// scanf("%llu%llu", &h, &w);
// scanf("%llu", &q);
// scanf("%s", s);
// scanf("%lld%lld", &va, &vb, &vc, &vd);
// scanf("%llu%llu%llu", &ua, &ub, &uc, &ud);
// scanf("%s", t);
// scanf("%lld", &m);
// for (i = 0; i < n; i++) {
// // scanf("%lld%lld", &xy[i].a, &xy[i].b);
// // scanf("%lld%lld%lld", &tup[i].a, &tup[i].b, &tup[i].c);
// scanf("%lld", &a[i]);
// scanf("%lld", &b[i]);
// // scanf("%lld", &c[i]);
// // scanf("%lld", &d[i]);
// a[i]--;
// b[i]--;
// // c[i]--;
// // d[i]--;
// // xy[i].a--;
// // xy[i].b--;
// // tup[i].a--;
// // tup[i].b--;
// }
// scanf("%llu", &m, &k);
// scanf("%llu", &q);
// scanf("%s", s);
// for (i = 0; i < n; i++) {
// scanf("%llu", &c[i]);
// // c[i]--;
// }
// scanf("%llu", &q);
// for (i = 0; i < q; i++) {
// scanf("%lld%lld", &xy[i].a, &xy[i].b);
// xy[i].a--;
// xy[i].b--;
// }
// for (i = 0; i < h; i++) {
// for (j = 0; j < w; j++) {
// scanf("%lld", &table[i][j]);
// // table[i][j]--;
// }
// }
// for (i = 0; i < h; i++) {
// scanf("%s", s[i]);
// }
// scanf("%llu", &q);
solve();
return 0;
}
Submission Info
Submission Time
2019-01-01 17:27:31+0900
Task
B - コメント
User
sheyasutaka
Language
C (GCC 5.4.1)
Score
90
Code Size
8215 Byte
Status
AC
Exec Time
1473 ms
Memory
14464 KB
Compile Error
./Main.c: In function ‘solve’:
./Main.c:374:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘sll {aka long int}’ [-Wformat=]
printf("%lld\n", result);
^
./Main.c: In function ‘main’:
./Main.c:405:8: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 2 has type ‘ull * {aka long unsigned int *}’ [-Wformat=]
scanf("%llu", &n, &m);
^
./Main.c:405:8: warning: too many arguments for format [-Wformat-extra-args]
./Main.c: In function ‘solve’:
./Main.c:363:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", sp[i]);
^
./Main.c: In function ‘main’:
./Main.c:405:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%llu", &n, &m);
^
Judge Result
Set Name
Sample
Subtask1
Subtask2
Score / Max Score
0 / 0
30 / 30
60 / 60
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt
Subtask1
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt
Subtask2
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.txt, subtask2_26.txt, subtask2_27.txt, subtask2_28.txt
Case Name
Status
Exec Time
Memory
sample_01.txt
AC
4 ms
14464 KB
sample_02.txt
AC
5 ms
14464 KB
subtask1_01.txt
AC
4 ms
14464 KB
subtask1_02.txt
AC
20 ms
14464 KB
subtask1_03.txt
AC
18 ms
14464 KB
subtask1_04.txt
AC
19 ms
14464 KB
subtask1_05.txt
AC
12 ms
14464 KB
subtask1_06.txt
AC
17 ms
14464 KB
subtask1_07.txt
AC
5 ms
14464 KB
subtask1_08.txt
AC
11 ms
14464 KB
subtask1_09.txt
AC
4 ms
14464 KB
subtask1_10.txt
AC
17 ms
14464 KB
subtask1_11.txt
AC
20 ms
14464 KB
subtask1_12.txt
AC
15 ms
14464 KB
subtask1_13.txt
AC
9 ms
14464 KB
subtask1_14.txt
AC
6 ms
14464 KB
subtask1_15.txt
AC
5 ms
14464 KB
subtask1_16.txt
AC
19 ms
14464 KB
subtask2_01.txt
AC
19 ms
14464 KB
subtask2_02.txt
AC
811 ms
14464 KB
subtask2_03.txt
AC
147 ms
14464 KB
subtask2_04.txt
AC
561 ms
14464 KB
subtask2_05.txt
AC
6 ms
14464 KB
subtask2_06.txt
AC
47 ms
14464 KB
subtask2_07.txt
AC
5 ms
14464 KB
subtask2_08.txt
AC
19 ms
14464 KB
subtask2_09.txt
AC
787 ms
14464 KB
subtask2_10.txt
AC
299 ms
14464 KB
subtask2_11.txt
AC
719 ms
14464 KB
subtask2_12.txt
AC
216 ms
14464 KB
subtask2_13.txt
AC
53 ms
14464 KB
subtask2_14.txt
AC
811 ms
14464 KB
subtask2_15.txt
AC
112 ms
14464 KB
subtask2_16.txt
AC
360 ms
14464 KB
subtask2_17.txt
AC
173 ms
14464 KB
subtask2_18.txt
AC
245 ms
14464 KB
subtask2_19.txt
AC
283 ms
14464 KB
subtask2_20.txt
AC
302 ms
14464 KB
subtask2_21.txt
AC
431 ms
14464 KB
subtask2_22.txt
AC
479 ms
14464 KB
subtask2_23.txt
AC
150 ms
14464 KB
subtask2_24.txt
AC
1111 ms
14464 KB
subtask2_25.txt
AC
433 ms
14464 KB
subtask2_26.txt
AC
197 ms
14464 KB
subtask2_27.txt
AC
1471 ms
14464 KB
subtask2_28.txt
AC
1473 ms
14464 KB