結果

問題 No.455 冬の大三角
ユーザー itezpaceitezpace
提出日時 2017-02-11 07:34:21
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,557 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 68,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 11:10:40
合計ジャッジ時間 4,339 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<pair<int,int>> calcLine(int h,int w,int x1,int y1,int x2,int y2){
  vector<pair<int,int>> vp;
  if(x1>x2){
    int xt=x2;
    x2=x1;
    x1=xt;
    int yt=y2;
    y2=y1;
    y1=yt;
  }
  if(x1==x2){
    for(int i=0;i<h;++i){
      if(i!=y1 && i!=y2) vp.push_back(make_pair(x1,i));
    }
  } else if(y1==y2){
    for(int i=0;i<w;++i){
      if(i!=x1 && i!=x2) vp.push_back(make_pair(i,y1));
    }
  } else {
    double a=(y2-y1)/(x2-x1);
    double b=y1-(a*x1);
    for(int i=0;i<w;++i){
      double c=a*i+b;
      int d=(int)c;
      double e=c-d;
      if(e==0 && e<h){
        vp.push_back(make_pair(i,e));
      }
    }
  }
  return vp;
}

int main() {
  int h,w;
  cin>>h>>w;
  int x1=-1,y1=-1,x2=-1,y2=-1;
  for(int i=0;i<h;++i){
    string s;
    cin>>s;
    for(int j=0;j<s.size();++j){
      if(s[j]=='*' && x1==-1){
        x1=j;
        y1=i;
      } else if(s[j]=='*' && x1!=-1){
        x2=j;
        y2=i;
        break;
      }
    }
  }
  vector<pair<int,int>> vp=calcLine(h,w,x1,y1,x2,y2);
  vector<vector<int>> vv(h,vector<int>(w));
  vv[y1][x1]=1;
  vv[y2][x2]=1;
  for(int i=0;i<vp.size();++i){
    if(vv[vp[i].second][vp[i].first]!=1) vv[vp[i].second][vp[i].first]=-1;
  }
  int f=0;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(vv[i][j]==1){
        cout<<"*";
      } else if(vv[i][j]==-1){
        cout<<"-";
      } else if(f==0){
        cout<<"*";
        f=1;
      } else {
        cout<<"-";
      }
    }
    cout<<endl;
  }
}
0