結果

問題 No.110 しましまピラミッド
ユーザー togatoga
提出日時 2015-08-03 22:58:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,852 bytes
コンパイル時間 1,229 ms
コンパイル使用メモリ 100,888 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 11:11:36
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp       make_pair
#define mt       make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,M;
vector<int> W,B;

int main(){
  cin >> N;
  W.resize(N);
  for (int i = 0; i < N; i++){
    cin >> W[i];
  }
  cin >> M;
  B.resize(M);
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }
  sort(W.rbegin(), W.rend());
  sort(B.rbegin(), B.rend());
  int res = 0;
  int cnt = 0;
  for (int cnt = 0; cnt < 2; cnt++){
    int width = 114514;
    stack<int> st;
    st.push(width);
    int b,w;
    b = w = 0;
    int color = cnt;
    while (true){//black
      if (color == 0){
	if (w < W.size()){
	  bool ok = false;
	  for (int i = w; i < W.size(); i++){
	    if (st.top() > W[i]){
	      w = i;
	      st.push(W[i]);
	      w++;
	      ok = true;
	      break;
	    }
	  }
	  if (!ok)break;
	}else{
	  break;
	}
      }else{
	if (b < B.size()){
	  bool ok = false;
	  for (int i = b; i < B.size(); i++){
	    if (st.top() > B[i]){
	      b = i;
	      st.push(B[i]);
	      b++;
	      ok = true;
	      break;
	    }
	  }
	  if (!ok)break;
	}else{
	  break;
	}
      }
      color = !color;
    }

    res = max(res, (int)st.size() - 1);
    while(!st.empty()){st.pop();}
  }
  cout << res << endl;
  return 0;
}
0