結果

問題 No.2509 Beam Shateki
ユーザー GOTKAKOGOTKAKO
提出日時 2023-10-20 23:35:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 3,051 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 188,808 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-20 23:36:25
合計ジャッジ時間 4,133 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 8 ms
6,944 KB
testcase_04 AC 8 ms
6,940 KB
testcase_05 AC 8 ms
6,944 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 8 ms
6,944 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 28 ms
6,940 KB
testcase_14 AC 29 ms
6,940 KB
testcase_15 AC 28 ms
6,940 KB
testcase_16 AC 27 ms
6,944 KB
testcase_17 AC 27 ms
6,944 KB
testcase_18 AC 28 ms
6,944 KB
testcase_19 AC 28 ms
6,944 KB
testcase_20 AC 28 ms
6,940 KB
testcase_21 AC 28 ms
6,940 KB
testcase_22 AC 28 ms
6,940 KB
testcase_23 AC 28 ms
6,940 KB
testcase_24 AC 28 ms
6,940 KB
testcase_25 AC 28 ms
6,940 KB
testcase_26 AC 28 ms
6,940 KB
testcase_27 AC 28 ms
6,940 KB
testcase_28 AC 28 ms
6,944 KB
testcase_29 AC 28 ms
6,940 KB
testcase_30 AC 27 ms
6,940 KB
testcase_31 AC 28 ms
6,940 KB
testcase_32 AC 27 ms
6,940 KB
testcase_33 AC 3 ms
6,944 KB
testcase_34 AC 11 ms
6,940 KB
testcase_35 AC 18 ms
6,940 KB
testcase_36 AC 7 ms
6,944 KB
testcase_37 AC 1 ms
6,944 KB
testcase_38 AC 8 ms
6,944 KB
testcase_39 AC 8 ms
6,940 KB
testcase_40 AC 13 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 9 ms
6,940 KB
testcase_43 AC 21 ms
6,940 KB
testcase_44 AC 23 ms
6,944 KB
testcase_45 AC 6 ms
6,940 KB
testcase_46 AC 11 ms
6,940 KB
testcase_47 AC 23 ms
6,944 KB
testcase_48 AC 10 ms
6,944 KB
testcase_49 AC 14 ms
6,944 KB
testcase_50 AC 15 ms
6,944 KB
testcase_51 AC 3 ms
6,944 KB
testcase_52 AC 12 ms
6,940 KB
testcase_53 AC 2 ms
6,944 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,940 KB
testcase_57 AC 1 ms
6,944 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,940 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,944 KB
testcase_63 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   75 |         auto [x1,y1,x2,y2,a1,b1,p1] = beam.at(i);
      |              ^
main.cpp:77:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   77 |             auto [x3,y3,x4,y4,a2,b2,p2] = beam.at(k);
      |                  ^
main.cpp:87:21: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   87 |                 auto[cx,cy] = crossP(p{x1+0.0,y1+0.0},p{x2+0.0,y2+0.0},p{x3+0.0,y3+0.0},p{x4+0.0,y4+0.0});
      |                     ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct p{ double x,y; };

p psub(p a,p b){ return {a.x-b.x,a.y-b.y};}

double dst(p a, p b, p c, p d){
    a = psub(a,b); c = psub(c,d);
    double ret = a.x*c.y - a.y*c.x;
    return ret;
}

pair<int,int> crossP(p a, p b, p c, p d){
    double D = dst(b,a,d,c), s = dst(c,a,d,c), t = dst(b,a,a,c);
    s /= D; t /= D;
    if(D == 0.0) return {-1e9,-1e9};
    if(s < 0.0 || 1.0 < s || t < 0.0 || 1.0 < t){return {-1e9,-1e9};}

    return {a.x + s*(b.x-a.x), a.y + s*(b.y-a.y)};  
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int H,W; cin >> H >> W;
    if(W == 1) swap(H,W);
    vector<vector<int>> A(H,vector<int>(W));
    for(auto &h : A) for(auto &w : h) cin >> w; 
    if(H == 1){
        int sum = 0;
        for(auto h : A) for(auto w : h) sum += w;
        cout << sum << endl; return 0;
    }

    vector<tuple<int,int,int,int,int,int,int>> beam;
    for(int i=0; i<H; i++){
        for(int k=0; k<W; k++){
            if(!(i == 0 || i == H-1 || k == 0 || k == W-1)) continue;

            bool one = true;
            for(int a=-1; a<=1; a++) for(int b=0; b<=1; b++){
                if(a == 0 && b == 0) continue;
                if(a == -1 && b != 1) continue;
                if(i == 0 && a == -1) continue;
                if(i != 0 && abs(a) == 1 && b == 0) continue;
                if(i == H-1 && a == 1) continue;
                if(k == W-1 && b == 1) continue;
                if(k == W-1 && i != 0) continue;
                
                if(a == 0 && b == 1 && k != 0) continue;
                if(a == 1 && b == 0 && i != 0) continue;

                int x = i, y = k, p = 0,grid = 0, i2 = 0,k2 = 0;
                while(true){
                    p += A.at(x).at(y); grid++;

                    x += a; y += b;
                    if(x < 0 || x >= H || y < 0 || y >= W){
                        i2 = x-a; k2  = y-b;
                        break;
                    }
                }
                if(!one && grid == 1) continue;
                if(one && grid == 1) one = false;
                
                beam.push_back({i,k,i2,k2,a,b,p});
            }
        }
    }

    int bs = beam.size(),answer = 0;
    for(int i=0; i<bs; i++){
        auto [x1,y1,x2,y2,a1,b1,p1] = beam.at(i);
        for(int k=i+1; k<bs; k++){
            auto [x3,y3,x4,y4,a2,b2,p2] = beam.at(k);
            
            int now = p1+p2; bool check = true;
            if(a1 == a2 && b1 == b2) check = false;
            set<pair<int,int>> ab,comp;
            ab.insert({a1,b1}); ab.insert({a2,b2});
            comp.insert({-1,1}); comp.insert({1,1});
            if(ab == comp && (x1+y1)%2 != (x3+y3)%2) check = false;
            
            if(check){
                auto[cx,cy] = crossP(p{x1+0.0,y1+0.0},p{x2+0.0,y2+0.0},p{x3+0.0,y3+0.0},p{x4+0.0,y4+0.0});
                if(cx >= 0 && cx < H && cy >= 0 && cy < W) now -= A.at(cx).at(cy);
            }
            answer = max(answer,now);
        }
    }
    cout << answer << endl;

 }
0