답안 #362784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362784 2021-02-04T11:31:48 Z Sparky_09 parentrises (BOI18_parentrises) C++17
0 / 100
1000 ms 876 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

const int MOD = 1e9+7;

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

void solve1(){
  return;
}

void add(int& a, int b) {
  a = (a + b) % MOD;
}

int mem[333][333][333];
int dp(int n, int open, int close){
  int &ret = mem[n][open][close];
  if(ret == -1) return ret;
  if(n == 0) return ret = close = 0;
  ret = 0;
  /*
    dp 
    n-1, open+2, close	add g open
    n-1, open, close+2	add g close
    n-1, open+1, close 	r/b open
		n-1, open+1, close 	r/b open
		n-1, open, close+1	r/b close
		n-1, open, close+1 	r/b close
		R ( )()
		B  ()( )
		ehhhhhhhhhhhhhhh
  */
  add(ret, dp(n - 1, open + 2, close));
  add(ret, dp(n - 1, open, close + 2));
	add(ret, dp(n - 1, open + 1, close));
	add(ret, dp(n - 1, open + 1, close));
	if(open > n - close){
		add(ret, dp(n - 1, open, close + 1));
		add(ret, dp(n - 1, open, close + 1));
	}	
	return ret;
}

void solve2(){
  /*
    green matters for both r and b
    so if we open r or b
    we close with r or b or g
    if we close with g
    then we close for both b and r since g is for both
    if we open g we close with either g
    or with both r and b 
  */
  int n;
  cin >> n;
  cout << dp(n, 0, 0) << '\n';
  return;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
  int ch;
  cin >> ch;
  int tc;
  cin >> tc;
  while(tc--){
    if(ch == 1){
      solve1();
    }
    else{
      solve2();
    }
  }

}

Compilation message

parentrises.cpp: In function 'void usaco(std::string)':
parentrises.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parentrises.cpp:16:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 876 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 876 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 876 KB Time limit exceeded