結果
問題 |
No.3275 Minesweeper on Graph
|
ユーザー |
![]() |
提出日時 | 2025-09-20 12:17:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,817 bytes |
コンパイル時間 | 497 ms |
コンパイル使用メモリ | 52,096 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-09-20 12:17:47 |
合計ジャッジ時間 | 4,013 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 WA * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:75:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:76:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 76 | for (int i = 0; i < n; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~ main.cpp:79:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 79 | scanf("%d%d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3275.cc: No.3275 Minesweeper on Graph - yukicoder */ #include<cstdio> #include<algorithm> #include<numeric> using namespace std; /* constant */ const int MAX_N = 16; /* typedef */ struct Rat { int a, b; Rat(): a(0), b(1) {} Rat(int _a): a(_a), b(1) {} Rat(int _a, int _b): a(_a), b(_b) { __normalize(); } void __normalize() { if (b == 0) a = 0; else { if (b < 0) a = -a, b = -b; int g = gcd(abs(a), b); a /= g, b /= g; } } Rat operator+(const Rat &r) const { return Rat(a * r.b + r.a * b, b * r.b); } Rat operator-(const Rat &r) const { return Rat(a * r.b - r.a * b, b * r.b); } Rat operator*(const Rat &r) const { return Rat(a * r.a, b * r.b); } Rat operator/(const Rat &r) const { return Rat(a * r.b, b * r.a); } void print() const { printf("%d", a); if (b > 1) printf("/%d", b); } }; /* global variables */ int as[MAX_N], bs[MAX_N]; Rat es[MAX_N][MAX_N], vs[MAX_N]; /* subroutines */ void swaprow(int n, int i, int j) { Rat tmp[MAX_N]; copy(es[i], es[i] + n, tmp); copy(es[j], es[j] + n, es[i]); copy(tmp, tmp + n, es[j]); swap(vs[i], vs[j]); } void printmat(int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) putchar(' '), es[i][j].print(); printf(" = "); vs[i].print(); putchar('\n'); } putchar('\n'); } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; es[u][v] = es[v][u] = 1; } for (int i = 0; i < n; i++) vs[i] = Rat(as[i]); //printmat(n); for (int j = 0, i0 = 0; j < n; j++) { if (! es[i0][j].a) { for (int i = i0 + 1; i < n; i++) if (es[i][j].a) { swaprow(n, i0, i); break; } if (! es[i0][j].a) continue; } if (es[i0][j].a != 1 || es[i0][j].b != 1) { auto e0 = es[i0][j]; for (int k = j; k < n; k++) es[i0][k] = es[i0][k] / e0; vs[i0] = vs[i0] / e0; } for (int i = i0 + 1; i < n; i++) if (es[i][j].a) { auto e0 = es[i][j]; for (int k = j; k < n; k++) es[i][k] = es[i][k] - es[i0][k] * e0; vs[i] = vs[i] - vs[i0] * e0; } //printf(" i0=%d\n", i0); printmat(n); i0++; } for (int i = n - 1; i >= 0; i--) { int j0 = 0; while (j0 < n && es[i][j0].a == 0) j0++; if (j0 >= n) { if (vs[i].a) { puts("No"); return 0; } } else { if (vs[i].b != 1) { puts("No"); return 0; } bs[j0] = vs[i].a; for (int k = i - 1; k >= 0; k--) if (es[k][j0].a) { vs[k] = vs[k] - es[k][j0] * vs[i]; es[k][j0] = 0; } } } //printmat(n); puts("Yes"); for (int i = 0; i < n; i++) printf("%d%c", bs[i], (i + 1 < n) ? ' ' : '\n'); return 0; }