답안 #152287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152287 2019-09-07T03:27:32 Z 12tqian Dango Maker (JOI18_dango_maker) C++14
33 / 100
24 ms 18424 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
const double PI = 4 * atan(1);
 
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
 
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
 
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
 
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const int MAX = 3005;
int grid[MAX][MAX];
int good [2][MAX][MAX];

int solve(vi& a, vi& b){
  int sz = sz(a);
  int ret = 0;
 /* if(sz<= 3){
    f0r(i,sz){
      ret += max(a[i], b[i]);
    }
    return ret;
  }*/
  int sum = 0;
  f0r(i, sz) sum += a[i];
  ret = max(sum, ret);
  sum = 0;
  f0r(i, sz) sum += b[i];
  ret = max(sum, ret);
  vi ptr;
  ptr.resize(sz);
  int p = -1;
  f0r(i, 3) ptr[i] = -1;
  f1r(i, 3, sz){
    if(b[i-3]) p = i-3;
    ptr[i] = p; 
  }
  vi dp;
  f0r(i, sz) dp.eb(0);
  vi mx;
  f0r(i, sz) mx.eb(0);
  vi post;
  vi pre;
  f0r(i, sz) pre.eb(0);
  f0r(i, sz) post.eb(0);
  for(int i = sz-1; i>= 0; i--){
    if(i == sz-1) post[i] = b[i];
    else post[i] = post[i+1] + b[i];
  }
  f0r(i, sz){
    if(i == 0) pre[i] = b[i];
    else pre[i] = pre[i-1] + b[i];
  }
  f0r(i, sz){
    if(i>3){
      dp[i] = pre[i-3] + a[i];
    }
    if(i == 0){
      if(a[i] == 1) dp[i] = max(dp[i], 1);
      mx[i] = dp[i];
      continue;
    }
    else if(i<3){
      dp[i] = max(dp[i], mx[i-1] + a[i]);
      mx[i] = max(mx[i-1], dp[i]);
      continue;
    }
    else if(i == 3){
      dp[i] = max(dp[i], max(mx[i-1] + a[i], a[i] + b[i-3]));
      mx[i] = max(mx[i-1], dp[i]);
      continue;
    }
    dp[i] = max(dp[i], max(mx[i-1], mx[i-4] + b[i-3]) + a[i]);
    mx[i] = max(mx[i-1], dp[i]);
  }
  f0r(i, sz){
    ret = max(ret, dp[i] + (i == sz-1? 0: post[i+1]));
  }
  return ret;
}


int main(){
	int n, m;
  cin >> n >> m;
  string temporary;
  getline(cin, temporary);
  f0r(i, n){
    string line;
    getline(cin, line);
    f0r(j, m){
      if(line[j] == 'R') grid[i][j] = 0;
      else if (line[j] == 'G') grid[i][j] = 1;
      else grid[i][j] = 2;
    }
  }
  f0r(i, n){
    f0r(j, m-2){
      if(grid[i][j] == 0 && grid[i][j+1] == 1 && grid[i][j+2] == 2) good[0][i][j] = 1;
    }
  }
  f0r(i, n-2){
    f0r(j, m){
      if(grid[i][j] == 0 && grid[i+1][j] == 1 && grid[i+2][j] == 2) good[1][i][j] = 1;
    }
  }
  int ans = 0;
  f0r(sum, m+n-1){
    vi a; //a connected to three behind inclusive
    vi b; //b conected to three ahead inclusive
    f0r(j, sum+1){
      int x = j;
      int y = sum - j;
      if(x<0 || y <0 || x>= n || y>=m) continue;
      a.eb(good[1][x][y]);
      b.eb(good[0][x][y]);
    }
    reverse(all(a));
    reverse(all(b));
    ans += solve(a, b);
    //cout << a << endl << b << endl << solve(a, b) << endl << endl;
  }
  cout << ans << endl;
	return 0;
}

Compilation message

dango_maker.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
dango_maker.cpp: In function 'void io(std::__cxx11::string)':
dango_maker.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 356 KB Output is correct
20 Correct 3 ms 440 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 424 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 504 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 356 KB Output is correct
20 Correct 3 ms 440 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 424 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 504 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 8 ms 504 KB Output is correct
55 Correct 24 ms 12920 KB Output is correct
56 Correct 11 ms 508 KB Output is correct
57 Incorrect 23 ms 18424 KB Output isn't correct
58 Halted 0 ms 0 KB -