답안 #152259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152259 2019-09-07T02:07:04 Z 12tqian Dango Maker (JOI18_dango_maker) C++14
0 / 100
2 ms 376 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;
  }
  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;
  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){
      if(a[i] == 1) dp[i] = 1;
      mx[i] = dp[i];
      continue;
    }
    else if(i<3){
      dp[i] = mx[i-1] + a[i];
      mx[i] = max(mx[i-1], dp[i]);
      continue;
    }
    else if(i == 3){
      dp[i] = max(mx[i-1], a[i] + b[i-3]);
      mx[i] = max(mx[i-1], dp[i]);
      continue;
    }
    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 dp[MAX][MAX];
int solve(vi& a, vi&b){
	int ret = 0;
  int sz = sz(a);
  //cout << a << " " << b << endl;
  a.insert(a.begin(), -1);
  b.insert(b.begin(), -1);
  f0r(i, sz+1) f0r(j, sz+1) dp[i][j] = 0;
  bool isTrue =false;
  f0r(i, sz+1) if(a[i] == 1){
  	isTrue = true;
  	break;
  	  }
  if(isTrue == false){
  	f1r(i, 1, sz+1) ret += b[i];
  	return ret;
  }
  isTrue = false;
  f0r(i, sz+1) if (b[i] == 1){
  	isTrue = true;
  	break;
  }
  if(isTrue == false){
  	f1r(i, 1, sz+1) ret += a[i];
  	return ret;
  }
  //cout << a<< " " << b << endl;
  f1r(i, 1, sz+1){
    f1r(j, 1, sz+1){
    	dp[i][j] = 0;
      if(a[i] == 1 && b[j] == 1 && !(i-j<=2 && i-j>= 0)){
        dp[i][j] = 2;
        f1r(k, 0, i-2){
          f1r(l, 0, j-2){
            dp[i][j] = max(dp[i][j], dp[k][l] + 2);
          }
        }
        ret = max(ret, dp[i][j]);
      }
    }
  }
  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, 2*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;
      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 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -