Submission #152292

# Submission time Handle Problem Language Result Execution time Memory
152292 2019-09-07T04:15:04 Z 12tqian Dango Maker (JOI18_dango_maker) C++14
100 / 100
1219 ms 115320 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;
const int INF = 1e9;
int grid[MAX][MAX];
int good [2][MAX][MAX];
vi pre;
inline int get(int l, int r){
	if(l>r) return 0;
	return pre[r] - (l == 0? 0: pre[l-1]);
}
int solve(vi&a, vi&b){
	int sz = sz(a);
	int ret = 0;
	vi dp;
	f0r(i, sz) dp.eb(0);
	pre.clear();
	f0r(i, sz) pre.eb(0);
	f0r(i, sz){
		if(i == 0) pre[i] = b[i];
		else pre[i] = pre[i-1] + b[i];
	}
	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);
//	cout << a << " " << b << " " << pre << endl;
	int mx = -INF;
	f0r(i, sz){
		if(i>2){
			mx = max(mx, dp[i-3] - pre[i-3]);
		}
		if(a[i] == 0){
			continue;
		}
		if(i>2) dp[i] = a[i] + get(0, i-3);
		else dp[i] = a[i];
		if(i>0){
			dp[i] = max(dp[i], dp[i-1] + a[i]);
		}
		if(i>1){
			dp[i] = max(dp[i], dp[i-2] + a[i]);
		}
		if(i>2){
			dp[i] = max(dp[i], mx + pre[i-3] + a[i]);
		}
		
	}
	f0r(i, sz){
		ret = max(ret, dp[i] + get(i+1, sz-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;
 /* int ones = 7;
  vi a; 
  vi b;
  f0r(i, ones){
  	a.eb(1);
  	b.eb(1);
  }
  cout << a << endl << b << endl << solve(a, b) << 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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 504 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 2 ms 376 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory 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 504 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 2 ms 376 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 248 KB Output is correct
20 Correct 3 ms 476 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 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 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 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 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 3 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 504 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 376 KB Output is correct
53 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory 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 504 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 2 ms 376 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 248 KB Output is correct
20 Correct 3 ms 476 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 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 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 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 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 3 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 504 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 376 KB Output is correct
53 Correct 2 ms 504 KB Output is correct
54 Correct 7 ms 376 KB Output is correct
55 Correct 24 ms 12920 KB Output is correct
56 Correct 9 ms 504 KB Output is correct
57 Correct 23 ms 18424 KB Output is correct
58 Correct 140 ms 24696 KB Output is correct
59 Correct 1207 ms 115092 KB Output is correct
60 Correct 1217 ms 115216 KB Output is correct
61 Correct 1219 ms 115264 KB Output is correct
62 Correct 7 ms 376 KB Output is correct
63 Correct 1169 ms 114904 KB Output is correct
64 Correct 1122 ms 115164 KB Output is correct
65 Correct 1156 ms 115228 KB Output is correct
66 Correct 1101 ms 115320 KB Output is correct
67 Correct 964 ms 60516 KB Output is correct
68 Correct 955 ms 60676 KB Output is correct
69 Correct 994 ms 70436 KB Output is correct
70 Correct 126 ms 25080 KB Output is correct
71 Correct 125 ms 25024 KB Output is correct
72 Correct 128 ms 25080 KB Output is correct
73 Correct 126 ms 25108 KB Output is correct
74 Correct 138 ms 25104 KB Output is correct
75 Correct 129 ms 25080 KB Output is correct
76 Correct 128 ms 25212 KB Output is correct
77 Correct 139 ms 25116 KB Output is correct
78 Correct 127 ms 25080 KB Output is correct
79 Correct 127 ms 25080 KB Output is correct
80 Correct 128 ms 25208 KB Output is correct
81 Correct 127 ms 25080 KB Output is correct
82 Correct 146 ms 25080 KB Output is correct
83 Correct 129 ms 25080 KB Output is correct
84 Correct 135 ms 25104 KB Output is correct
85 Correct 126 ms 25128 KB Output is correct
86 Correct 141 ms 25092 KB Output is correct
87 Correct 128 ms 25108 KB Output is correct
88 Correct 140 ms 25100 KB Output is correct
89 Correct 128 ms 25180 KB Output is correct
90 Correct 127 ms 25112 KB Output is correct