AtCoder Beginner Contest 008

Submission #4241786

Source codeソースコード

using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>V[I]
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>inline T lcm(T a,T b){return a*b/gcd(b,a%b);}

int W,H,N;
vector<int> X,Y;
map<tuple<int, int, int, int>, int> dp;

int rec(int lx,int ly,int rx,int ry){
  if(dp.count(tie(lx,ly,rx,ry)))return dp[tie(lx,ly,rx,ry)];
  int res=0;
  int i;
  REP(i,N){
    if(X[i]>=lx&&X[i]<rx&&Y[i]>=ly&&Y[i]<ry){
      int lu=rec(lx,Y[i]+1,X[i],ry);
      int ld=rec(lx,ly,X[i],Y[i]);
      int ru=rec(X[i]+1,Y[i]+1,rx,ry);
      int rd=rec(X[i]+1,ly,rx,Y[i]);
      chmax(res,lu+ld+ru+rd+rx-lx+ry-ly-1);
    }
  }
  return dp[tie(lx,ly,rx,ry)]=res;
}
inline void solve(){
  int i;
  IN3(W,H,N);
  X.resize(N);
  Y.resize(N);
  REP(i,N){
    IN2(X[i],Y[i]);
    X[i]--;Y[i]--;
  }
  OUT(rec(0,0,W,H));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}

Submission

Task問題 D - 金塊ゲーム
User nameユーザ名 hryshtk
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1987 Byte
File nameファイル名
Exec time実行時間 23 ms
Memory usageメモリ使用量 896 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
Subtask1 80 / 80 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt
Subtask2 19 / 19 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt,subtask2_23.txt,subtask2_24.txt,subtask2_25.txt
Subtask3 1 / 1 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt,subtask2_23.txt,subtask2_24.txt,subtask2_25.txt,subtask3_01.txt,subtask3_02.txt,subtask3_03.txt,subtask3_04.txt,subtask3_05.txt,subtask3_06.txt,subtask3_07.txt,subtask3_08.txt,subtask3_09.txt,subtask3_10.txt,subtask3_11.txt,subtask3_12.txt,subtask3_13.txt,subtask3_14.txt,subtask3_15.txt,subtask3_16.txt,subtask3_17.txt,subtask3_18.txt,subtask3_19.txt,subtask3_20.txt,subtask3_21.txt,subtask3_22.txt,subtask3_23.txt,subtask3_24.txt,subtask3_25.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 1 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt AC 1 ms 256 KB
subtask1_10.txt AC 1 ms 256 KB
subtask1_11.txt AC 1 ms 256 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 256 KB
subtask1_14.txt AC 1 ms 256 KB
subtask1_15.txt AC 1 ms 256 KB
subtask1_16.txt AC 1 ms 256 KB
subtask1_17.txt AC 1 ms 256 KB
subtask1_18.txt AC 1 ms 256 KB
subtask1_19.txt AC 1 ms 256 KB
subtask1_20.txt AC 1 ms 256 KB
subtask1_21.txt AC 1 ms 256 KB
subtask1_22.txt AC 1 ms 256 KB
subtask1_23.txt AC 1 ms 256 KB
subtask1_24.txt AC 1 ms 256 KB
subtask1_25.txt AC 1 ms 256 KB
subtask2_01.txt AC 3 ms 384 KB
subtask2_02.txt AC 3 ms 384 KB
subtask2_03.txt AC 5 ms 512 KB
subtask2_04.txt AC 5 ms 512 KB
subtask2_05.txt AC 8 ms 512 KB
subtask2_06.txt AC 11 ms 640 KB
subtask2_07.txt AC 11 ms 640 KB
subtask2_08.txt AC 11 ms 640 KB
subtask2_09.txt AC 22 ms 896 KB
subtask2_10.txt AC 21 ms 896 KB
subtask2_11.txt AC 21 ms 896 KB
subtask2_12.txt AC 22 ms 896 KB
subtask2_13.txt AC 11 ms 640 KB
subtask2_14.txt AC 11 ms 640 KB
subtask2_15.txt AC 2 ms 256 KB
subtask2_16.txt AC 11 ms 640 KB
subtask2_17.txt AC 22 ms 896 KB
subtask2_18.txt AC 23 ms 896 KB
subtask2_19.txt AC 21 ms 896 KB
subtask2_20.txt AC 21 ms 896 KB
subtask2_21.txt AC 22 ms 896 KB
subtask2_22.txt AC 21 ms 896 KB
subtask2_23.txt AC 22 ms 896 KB
subtask2_24.txt AC 22 ms 896 KB
subtask2_25.txt AC 23 ms 896 KB
subtask3_01.txt AC 1 ms 256 KB
subtask3_02.txt AC 3 ms 384 KB
subtask3_03.txt AC 3 ms 384 KB
subtask3_04.txt AC 4 ms 384 KB
subtask3_05.txt AC 7 ms 512 KB
subtask3_06.txt AC 5 ms 512 KB
subtask3_07.txt AC 5 ms 512 KB
subtask3_08.txt AC 11 ms 640 KB
subtask3_09.txt AC 12 ms 640 KB
subtask3_10.txt AC 22 ms 896 KB
subtask3_11.txt AC 20 ms 896 KB
subtask3_12.txt AC 23 ms 896 KB
subtask3_13.txt AC 22 ms 896 KB
subtask3_14.txt AC 22 ms 896 KB
subtask3_15.txt AC 22 ms 896 KB
subtask3_16.txt AC 21 ms 896 KB
subtask3_17.txt AC 22 ms 896 KB
subtask3_18.txt AC 8 ms 512 KB
subtask3_19.txt AC 20 ms 896 KB
subtask3_20.txt AC 11 ms 640 KB
subtask3_21.txt AC 22 ms 896 KB
subtask3_22.txt AC 22 ms 896 KB
subtask3_23.txt AC 21 ms 896 KB
subtask3_24.txt AC 21 ms 896 KB
subtask3_25.txt AC 20 ms 896 KB