LoginSignup
0
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 267

Last updated at Posted at 2022-09-05

A - Saturday

O(1)

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

string S[5] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};

int main() {
    string s;
    cin >> s;

    int ans=0;
    rep(i, 5){
        if(s == S[i]){
            ans = 5 - i;
        }
    }
    cout << ans << endl;

    return 0;
} 

B - Split?

O(1)

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;

    if(s[0] == '1'){
        cout << "No" << endl;
        return 0;
    }

    if( (s[6] == '1' && s[3] == '0') ||
        (s[3] == '1' && s[1] == '0' && s[7] == '0') ||
        (s[9] == '1' && s[5] == '0') ||
        (s[5] == '1' && s[2] == '0' && s[8] == '0') ||
        ((s[1] == '1' || s[7] == '1') && s[4] == '0') ||
        ((s[2] == '1' || s[8] == '1') && s[4] == '0')
    ){
        cout << "Yes" << endl;       
        return 0;
    }
    cout << "No" << endl;

    return 0;
} 

C - Index × A(Continuous ver.)

O(N)

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), S(N+1), AA(N+1);
    rep(i, N) cin >> A[i];
    rep(i, N) AA[i+1] = AA[i] + A[i];
    ll total = 0;
    rep(i, M) total += A[i]*(i+1);
    ll res = total;
    repx(i, 1, N+1){
        if(i+M>N) break;
        total = total - (AA[M+i-1]-AA[i-1]) + A[M+i-1]*M;
        res = max(res, total);
    }
    cout << res << endl;
    return 0;
} 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0