結果

問題 No.607 開通777年記念
ユーザー aim_cpoaim_cpo
提出日時 2017-12-07 12:17:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 165,248 KB
実行使用メモリ 11,448 KB
最終ジャッジ日時 2023-08-19 12:06:09
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 17 ms
7,720 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 84 ms
11,188 KB
testcase_12 AC 78 ms
11,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
ll a[1001][1001];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
   cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
 cin>>n>>m;
 for(int i=0;i<m;i++){
  for(int j=0;j<n;j++){
   cin>>a[i][j];
   if(i!=0)a[i][j]+=a[i-1][j];
  }
 }
 for(int i=0;i<m;i++){
  int r=0,l=0;
  ll sum=0;
  while(r<n){
   //show(sum);
   if(sum==777){
    cout<<"YES"<<"\n";
    return 0;
   }
   if(sum+a[i][r]<=777){
    sum+=a[i][r];
    r++;
   }else{
    while(sum+a[i][r]>777){
     if(r==l){
      break;
     }
     sum-=a[i][l];
     l++;
    }
    sum+=a[i][r];
    r++;
   }
  }
  if(sum==777){
   cout<<"YES"<<"\n";
   return 0;
  }
 }
 cout<<"NO"<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
0