結果

問題 No.455 冬の大三角
ユーザー ManjushriMitraManjushriMitra
提出日時 2024-08-10 11:26:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,455 bytes
コンパイル時間 3,262 ms
コンパイル使用メモリ 248,260 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-10 11:26:30
合計ジャッジ時間 5,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:96:32: warning: 'ans_x' may be used uninitialized [-Wmaybe-uninitialized]
   96 |             if(y == ans_y && x == ans_x) cout << "*";
      |                              ~~^~~~~~~~
main.cpp:48:16: note: 'ans_x' was declared here
   48 |     int ans_y, ans_x;
      |                ^~~~~
main.cpp:96:18: warning: 'ans_y' may be used uninitialized [-Wmaybe-uninitialized]
   96 |             if(y == ans_y && x == ans_x) cout << "*";
      |                ~~^~~~~~~~
main.cpp:48:9: note: 'ans_y' was declared here
   48 |     int ans_y, ans_x;
      |         ^~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<n; ++i)
#define repl(i,m,n) for(ll i=m; i<n; ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const int inf = int(1e9);

int gcd(int a, int b){
    return a % b ? gcd(b, a % b) : b;
}

pair<int, int> slope(int y1, int x1, int y2, int x2){
    int y = y2 - y1, x = x2 - x1;
    if(x == 0) return {inf, 0};
    if(y == 0) return {0, inf};
    else{
        int g = gcd(abs(y), abs(x));
        return {y/g, x/g};
    }
}

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, 0, H) cin >> S[i];

    int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
    bool fin = false;
    rep(y, 0, H){
        rep(x, 0, W){
            if(S[y][x] == '*'){
                if(x1 == -1){
                    x1 = x, y1 = y;
                }else{
                    x2 = x, y2 = y;
                    fin = true;
                    break;
                }
            }
        }
        if(fin) break;
    }

    int ans_y, ans_x;
    fin = false;
    if(y1 == y2){
        rep(y, 0, H){
            rep(x, 0, W){
                if(y == y1 && x == x1) continue;
                if(y == y2 && x == x2) continue;
                if(y != y1){
                    ans_y = y, ans_x = x;
                    fin = true;
                    break;
                }
            }
            if(fin) break;
        }
    }else if(x1 == x2){
        rep(y, 0, H){
            rep(x, 0, W){
                if(y == y1 && x == x1) continue;
                if(y == y2 && x == x2) continue;
                if(x != x1){
                    ans_y = y, ans_x = x;
                    fin = true;
                    break;
                }
            }
            if(fin) break;
        }
    }else{
        auto s1 = slope(y1, x1, y2, x2);

        rep(y, 0, H){
            rep(x, 0, W){
                if(y == y1 && x == x1) continue;
                if(y == y2 && x == x2) continue;
                auto s = slope(y, x, y1, x1);
                if(s != s1){
                    ans_y = y, ans_x = x;
                    fin = true;
                    break;
                }
            }
            if(fin) break;
        }
    }

    rep(y, 0, H){
        rep(x, 0, W){
            if(y == ans_y && x == ans_x) cout << "*";
            else cout << S[y][x];
        }
        cout << endl;
    }
    return 0;
}
0