Submission #1204145
Source Code Expand
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int dp[310][310], cost[310][310]; char v[310][310]; int main () { //freopen ("file.in", "r", stdin); int n, m; scanf ("%d %d\n", &n, &m); for (int i = 1; i <= n; ++i) fgets (v[i] + 1, 310, stdin); int rez = 0; for (int j = 1; j < m; ++j) { for (int a = 0; a <= n; ++a) for (int b = 0; b <= n; ++b) dp[a][b] = 2000000000, cost[a][b] = 0; for (int a = 0; a <= n; ++a) { for (int b = a + 1; b <= n; ++b) { cost[0][a] += (v[b][j] == v[b - a][j + 1]); if (a > 0) cost[a][0] += (v[b - a][j] == v[b][j + 1]); } } for (int a = 1; a <= n; ++a) for (int b = 1; b <= n; ++b) cost[a][b] = cost[a - 1][b - 1] - (v[n - a + 1][j] == v[n - b + 1][j + 1]); dp[0][0] = 0; for (int a = 0; a <= n; ++a) for (int b = 0; b <= n; ++b) { if (!a && !b) continue; if (a > 0) dp[a][b] = min (dp[a][b], dp[a - 1][b] + cost[a - 1][b]); if (b > 0) dp[a][b] = min (dp[a][b], dp[a][b - 1] + cost[a][b - 1]); } rez += dp[n][n]; } printf ("%d\n", rez); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Friction |
User | Theodor1000 |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 1417 Byte |
Status | AC |
Exec Time | 195 ms |
Memory | 1024 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:15:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d %d\n", &n, &m); ^ ./Main.cpp:18:37: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] fgets (v[i] + 1, 310, stdin); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 500 / 500 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt |
Subtask | 0_000.txt, 0_001.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 0 ms | 128 KB |
0_001.txt | AC | 1 ms | 128 KB |
0_002.txt | AC | 0 ms | 128 KB |
0_003.txt | AC | 0 ms | 128 KB |
0_004.txt | AC | 0 ms | 128 KB |
1_005.txt | AC | 0 ms | 128 KB |
1_006.txt | AC | 2 ms | 1024 KB |
1_007.txt | AC | 2 ms | 1024 KB |
1_008.txt | AC | 2 ms | 1024 KB |
1_009.txt | AC | 2 ms | 1024 KB |
1_010.txt | AC | 2 ms | 1024 KB |
1_011.txt | AC | 2 ms | 896 KB |
1_012.txt | AC | 2 ms | 1024 KB |
1_013.txt | AC | 1 ms | 640 KB |
1_014.txt | AC | 2 ms | 1024 KB |
1_015.txt | AC | 1 ms | 768 KB |
1_016.txt | AC | 2 ms | 1024 KB |
1_017.txt | AC | 1 ms | 256 KB |
1_018.txt | AC | 2 ms | 1024 KB |
1_019.txt | AC | 1 ms | 640 KB |
1_020.txt | AC | 2 ms | 1024 KB |
1_021.txt | AC | 2 ms | 1024 KB |
1_022.txt | AC | 2 ms | 1024 KB |
2_023.txt | AC | 0 ms | 128 KB |
2_024.txt | AC | 195 ms | 1024 KB |
2_025.txt | AC | 195 ms | 1024 KB |
2_026.txt | AC | 195 ms | 1024 KB |
2_027.txt | AC | 195 ms | 1024 KB |
2_028.txt | AC | 195 ms | 1024 KB |
2_029.txt | AC | 7 ms | 256 KB |
2_030.txt | AC | 195 ms | 1024 KB |
2_031.txt | AC | 6 ms | 256 KB |
2_032.txt | AC | 195 ms | 1024 KB |
2_033.txt | AC | 45 ms | 640 KB |
2_034.txt | AC | 195 ms | 1024 KB |
2_035.txt | AC | 112 ms | 1024 KB |
2_036.txt | AC | 195 ms | 1024 KB |
2_037.txt | AC | 6 ms | 512 KB |
2_038.txt | AC | 195 ms | 1024 KB |
2_039.txt | AC | 4 ms | 384 KB |
2_040.txt | AC | 195 ms | 1024 KB |