Submission #11048886
Source Code Expand
Copy
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
const int N = 120;
char s[N][N];
int dp[N][N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", s[i]);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dp[i][j] = INF;
if (i == 0 && j == 0) {
dp[i][j] = s[i][j] == '#';
continue;
}
if (i - 1 >= 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'));
}
if (j - 1 >= 0) {
dp[i][j] = min(dp[i][j], dp[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
}
}
}
printf("%d\n", dp[n - 1][m - 1]);
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Range Flip Find Route |
User |
cuiaoxiang |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
3116 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
384 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:96:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:98:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00, example_01, example_02, example_03 |
All |
corner_00, corner_01, example_00, example_01, example_02, example_03, kuronuri_00, max_answer_00, max_answer_01, max_answer_02, max_random_00, max_random_01, max_random_02, max_random_03, one_path_00, one_path_01, one_path_02 |
Case Name |
Status |
Exec Time |
Memory |
corner_00 |
AC |
1 ms |
384 KB |
corner_01 |
AC |
1 ms |
384 KB |
example_00 |
AC |
1 ms |
256 KB |
example_01 |
AC |
1 ms |
256 KB |
example_02 |
AC |
1 ms |
256 KB |
example_03 |
AC |
1 ms |
256 KB |
kuronuri_00 |
AC |
1 ms |
384 KB |
max_answer_00 |
AC |
1 ms |
384 KB |
max_answer_01 |
AC |
1 ms |
384 KB |
max_answer_02 |
AC |
1 ms |
384 KB |
max_random_00 |
AC |
1 ms |
384 KB |
max_random_01 |
AC |
1 ms |
384 KB |
max_random_02 |
AC |
1 ms |
384 KB |
max_random_03 |
AC |
1 ms |
384 KB |
one_path_00 |
AC |
1 ms |
384 KB |
one_path_01 |
AC |
1 ms |
384 KB |
one_path_02 |
AC |
1 ms |
384 KB |