답안 #216581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216581 2020-03-27T15:10:42 Z toxic_hack Dango Maker (JOI18_dango_maker) C++14
100 / 100
573 ms 125304 KB
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}


const int N = 3003;

int dp[N][N][3];

int n, m;
string arr[N];
string s = "RGW";
int hori_valid(int i, int j) {
    int done = 0;
    for (int k = j - 1; k < j + 2; k++) {
        if (k < 0 || k >= m || arr[i][k] != s[k - j + 1]) {
            done = 1;
            break;
        }
    }
    return (done == 0);
}

int vert_valid(int i, int j) {
    int done = 0;
    for (int k = i - 1; k < i + 2; k++) {
        if (k < 0 || k >= n || arr[k][j] != s[k - i + 1]) {
            done = 1;
            break;
        }
    }
    return (done == 0);
}

// 0-> noting 1-> hori, 2 -> vertical

int f(int i, int j, int k) {
    if (i >= n || i < 0 || j >= m || j < 0) return 0;
    int &ans = dp[i][j][k];
    if (ans != -1) return ans;
    ans = 0;
    if (k == 0) {
        if (hori_valid(i, j)) {
            ans = 1 + f(i - 1, j + 1, 1);
        }
        if (vert_valid(i, j)) {
            ans = max(ans, 1 + f(i - 1, j + 1, 2));
        }
        ans = max(ans, f(i - 1, j + 1, 0));
    } else if (k == 1) {
        if (hori_valid(i, j)) {
            ans = 1 + f(i - 1, j + 1, 1);
        }
        ans = max(ans, f(i - 1, j + 1, 0));
    } else {
        if (vert_valid(i, j)) {
            ans = 1 + f(i - 1, j + 1, 2);
        }
        ans = max(ans, f(i - 1, j + 1, 0));
    }
    return ans;
}

int solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    MEMS(dp, -1);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += f(i, 0, 0);
    }
    for (int j = 1; j < m; j++) {
        ans += f(n - 1, j, 0);
    }
    cout << ans << endl;
    return 0;
}

int32_t main(){ _
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 106360 KB Output is correct
2 Correct 55 ms 106360 KB Output is correct
3 Correct 55 ms 106408 KB Output is correct
4 Correct 55 ms 106360 KB Output is correct
5 Correct 57 ms 106360 KB Output is correct
6 Correct 58 ms 106492 KB Output is correct
7 Correct 56 ms 106364 KB Output is correct
8 Correct 56 ms 106360 KB Output is correct
9 Correct 56 ms 106360 KB Output is correct
10 Correct 58 ms 106360 KB Output is correct
11 Correct 55 ms 106360 KB Output is correct
12 Correct 55 ms 106360 KB Output is correct
13 Correct 57 ms 106360 KB Output is correct
14 Correct 55 ms 106360 KB Output is correct
15 Correct 55 ms 106360 KB Output is correct
16 Correct 56 ms 106360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 106360 KB Output is correct
2 Correct 55 ms 106360 KB Output is correct
3 Correct 55 ms 106408 KB Output is correct
4 Correct 55 ms 106360 KB Output is correct
5 Correct 57 ms 106360 KB Output is correct
6 Correct 58 ms 106492 KB Output is correct
7 Correct 56 ms 106364 KB Output is correct
8 Correct 56 ms 106360 KB Output is correct
9 Correct 56 ms 106360 KB Output is correct
10 Correct 58 ms 106360 KB Output is correct
11 Correct 55 ms 106360 KB Output is correct
12 Correct 55 ms 106360 KB Output is correct
13 Correct 57 ms 106360 KB Output is correct
14 Correct 55 ms 106360 KB Output is correct
15 Correct 55 ms 106360 KB Output is correct
16 Correct 56 ms 106360 KB Output is correct
17 Correct 60 ms 106360 KB Output is correct
18 Correct 58 ms 106360 KB Output is correct
19 Correct 55 ms 106360 KB Output is correct
20 Correct 55 ms 106360 KB Output is correct
21 Correct 56 ms 106360 KB Output is correct
22 Correct 55 ms 106360 KB Output is correct
23 Correct 58 ms 106360 KB Output is correct
24 Correct 56 ms 106360 KB Output is correct
25 Correct 57 ms 106360 KB Output is correct
26 Correct 56 ms 106360 KB Output is correct
27 Correct 56 ms 106360 KB Output is correct
28 Correct 56 ms 106360 KB Output is correct
29 Correct 56 ms 106360 KB Output is correct
30 Correct 57 ms 106360 KB Output is correct
31 Correct 55 ms 106360 KB Output is correct
32 Correct 55 ms 106360 KB Output is correct
33 Correct 56 ms 106360 KB Output is correct
34 Correct 57 ms 106360 KB Output is correct
35 Correct 56 ms 106364 KB Output is correct
36 Correct 56 ms 106360 KB Output is correct
37 Correct 55 ms 106360 KB Output is correct
38 Correct 55 ms 106360 KB Output is correct
39 Correct 56 ms 106360 KB Output is correct
40 Correct 56 ms 106360 KB Output is correct
41 Correct 55 ms 106360 KB Output is correct
42 Correct 56 ms 106360 KB Output is correct
43 Correct 55 ms 106252 KB Output is correct
44 Correct 55 ms 106360 KB Output is correct
45 Correct 55 ms 106360 KB Output is correct
46 Correct 56 ms 106360 KB Output is correct
47 Correct 59 ms 106488 KB Output is correct
48 Correct 55 ms 106376 KB Output is correct
49 Correct 56 ms 106360 KB Output is correct
50 Correct 55 ms 106360 KB Output is correct
51 Correct 55 ms 106368 KB Output is correct
52 Correct 55 ms 106360 KB Output is correct
53 Correct 62 ms 106360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 106360 KB Output is correct
2 Correct 55 ms 106360 KB Output is correct
3 Correct 55 ms 106408 KB Output is correct
4 Correct 55 ms 106360 KB Output is correct
5 Correct 57 ms 106360 KB Output is correct
6 Correct 58 ms 106492 KB Output is correct
7 Correct 56 ms 106364 KB Output is correct
8 Correct 56 ms 106360 KB Output is correct
9 Correct 56 ms 106360 KB Output is correct
10 Correct 58 ms 106360 KB Output is correct
11 Correct 55 ms 106360 KB Output is correct
12 Correct 55 ms 106360 KB Output is correct
13 Correct 57 ms 106360 KB Output is correct
14 Correct 55 ms 106360 KB Output is correct
15 Correct 55 ms 106360 KB Output is correct
16 Correct 56 ms 106360 KB Output is correct
17 Correct 60 ms 106360 KB Output is correct
18 Correct 58 ms 106360 KB Output is correct
19 Correct 55 ms 106360 KB Output is correct
20 Correct 55 ms 106360 KB Output is correct
21 Correct 56 ms 106360 KB Output is correct
22 Correct 55 ms 106360 KB Output is correct
23 Correct 58 ms 106360 KB Output is correct
24 Correct 56 ms 106360 KB Output is correct
25 Correct 57 ms 106360 KB Output is correct
26 Correct 56 ms 106360 KB Output is correct
27 Correct 56 ms 106360 KB Output is correct
28 Correct 56 ms 106360 KB Output is correct
29 Correct 56 ms 106360 KB Output is correct
30 Correct 57 ms 106360 KB Output is correct
31 Correct 55 ms 106360 KB Output is correct
32 Correct 55 ms 106360 KB Output is correct
33 Correct 56 ms 106360 KB Output is correct
34 Correct 57 ms 106360 KB Output is correct
35 Correct 56 ms 106364 KB Output is correct
36 Correct 56 ms 106360 KB Output is correct
37 Correct 55 ms 106360 KB Output is correct
38 Correct 55 ms 106360 KB Output is correct
39 Correct 56 ms 106360 KB Output is correct
40 Correct 56 ms 106360 KB Output is correct
41 Correct 55 ms 106360 KB Output is correct
42 Correct 56 ms 106360 KB Output is correct
43 Correct 55 ms 106252 KB Output is correct
44 Correct 55 ms 106360 KB Output is correct
45 Correct 55 ms 106360 KB Output is correct
46 Correct 56 ms 106360 KB Output is correct
47 Correct 59 ms 106488 KB Output is correct
48 Correct 55 ms 106376 KB Output is correct
49 Correct 56 ms 106360 KB Output is correct
50 Correct 55 ms 106360 KB Output is correct
51 Correct 55 ms 106368 KB Output is correct
52 Correct 55 ms 106360 KB Output is correct
53 Correct 62 ms 106360 KB Output is correct
54 Correct 55 ms 106360 KB Output is correct
55 Correct 56 ms 106360 KB Output is correct
56 Correct 54 ms 106360 KB Output is correct
57 Correct 57 ms 106360 KB Output is correct
58 Correct 89 ms 108408 KB Output is correct
59 Correct 498 ms 125048 KB Output is correct
60 Correct 497 ms 125176 KB Output is correct
61 Correct 487 ms 125048 KB Output is correct
62 Correct 57 ms 106360 KB Output is correct
63 Correct 462 ms 124408 KB Output is correct
64 Correct 570 ms 125176 KB Output is correct
65 Correct 573 ms 125136 KB Output is correct
66 Correct 572 ms 125048 KB Output is correct
67 Correct 502 ms 125304 KB Output is correct
68 Correct 473 ms 125048 KB Output is correct
69 Correct 481 ms 125048 KB Output is correct
70 Correct 94 ms 108408 KB Output is correct
71 Correct 105 ms 108412 KB Output is correct
72 Correct 97 ms 108500 KB Output is correct
73 Correct 99 ms 108408 KB Output is correct
74 Correct 95 ms 108408 KB Output is correct
75 Correct 99 ms 108664 KB Output is correct
76 Correct 94 ms 108408 KB Output is correct
77 Correct 94 ms 108408 KB Output is correct
78 Correct 95 ms 108504 KB Output is correct
79 Correct 93 ms 108408 KB Output is correct
80 Correct 99 ms 108640 KB Output is correct
81 Correct 95 ms 108408 KB Output is correct
82 Correct 101 ms 108408 KB Output is correct
83 Correct 97 ms 108536 KB Output is correct
84 Correct 97 ms 108408 KB Output is correct
85 Correct 96 ms 108408 KB Output is correct
86 Correct 94 ms 108408 KB Output is correct
87 Correct 98 ms 108408 KB Output is correct
88 Correct 99 ms 108584 KB Output is correct
89 Correct 95 ms 108408 KB Output is correct
90 Correct 92 ms 108412 KB Output is correct