Submission #152285

# Submission time Handle Problem Language Result Execution time Memory
152285 2019-09-07T03:26:29 Z 12tqian Dango Maker (JOI18_dango_maker) C++14
Compilation error
0 ms 0 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, n){
    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 'int solve(std::vector<int>&, std::vector<int>&)':
dango_maker.cpp:95:10: error: 'n' was not declared in this scope
   f0r(i, n){
          ^
dango_maker.cpp:33:32: note: in definition of macro 'f0r'
 #define f0r(i,a) for(int i=0;i<a;i++)
                                ^
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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~