結果

問題 No.110 しましまピラミッド
ユーザー hogeover30hogeover30
提出日時 2014-12-23 23:27:14
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 821 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 51,284 KB
最終ジャッジ日時 2023-08-30 03:44:00
合計ジャッジ時間 721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:5:16: error: ‘vector’ does not name a type; did you mean ‘perror’?
 int func(const vector<int>& a, const vector<int>& b)
                ^~~~~~
                perror
main.cpp:5:22: error: expected ‘,’ or ‘...’ before ‘<’ token
 int func(const vector<int>& a, const vector<int>& b)
                      ^
main.cpp: In function ‘int func(int)’:
main.cpp:7:11: error: ‘a’ was not declared in this scope
     int n=a.size(), m=b.size();
           ^
main.cpp:12:36: error: ‘b’ was not declared in this scope
             while (ai<n and a[ai]>=b[bi]) ++ai;
                                    ^
main.cpp:12:36: note: suggested alternative: ‘bi’
             while (ai<n and a[ai]>=b[bi]) ++ai;
                                    ^
                                    bi
main.cpp:17:23: error: ‘m’ was not declared in this scope
             while (bi<m and b[bi]>=a[ai]) ++bi;
                       ^
main.cpp:17:29: error: ‘b’ was not declared in this scope
             while (bi<m and b[bi]>=a[ai]) ++bi;
                             ^
main.cpp:17:29: note: suggested alternative: ‘bi’
             while (bi<m and b[bi]>=a[ai]) ++bi;
                             ^
                             bi
main.cpp:18:21: error: ‘m’ was not declared in this scope
             if (bi==m) break;
                     ^
main.cpp: In function ‘int main()’:
main.cpp:29:5: error: ‘vector’ was not declared in this scope
     vector<int> w(n);
     ^~~~~~
main.cpp:29:5: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:29:5:
     vector<int> w(n);
     ^~~~~~
main.cpp:29:12: error: expected primary-expression before ‘int’
     vector<int> w(n);
            ^~~
main.cpp:30:17: error: ‘w’ was not declared in this scope
     for(int& v: w) cin>>v;
                 ^
main.cpp:31:16: error: ‘w’ was not declar

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int func(const vector<int>& a, const vector<int>& b)
{
    int n=a.size(), m=b.size();
    int f=0, ai=0, bi=0;
    int res=1, len=a[ai];
    while (true) {
        if (f) {
            while (ai<n and a[ai]>=b[bi]) ++ai;
            if (ai==n) break;
            ++res;
        }
        else {
            while (bi<m and b[bi]>=a[ai]) ++bi;
            if (bi==m) break;
            ++res;
        }
        f^=1;
    }
    return res;
}

int main()
{
    int n; cin>>n;
    vector<int> w(n);
    for(int& v: w) cin>>v;
    sort(begin(w), end(w));
    reverse(begin(w), end(w));

    int m; cin>>m;
    vector<int> b(m);
    for(int& v: b) cin>>v;
    sort(begin(b), end(b));
    reverse(begin(b), end(b));

    cout<<max(func(w, b), func(b, w))<<endl;
}
0