LoginSignup
0
0

More than 1 year has passed since last update.

AtCoder Beginner Contest 255

Last updated at Posted at 2022-06-17

A - You should output ARC, though this is ABC.

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() {
    int R, C;
    cin >> R >> C;
    int A[2][2];
    rep(i, 2) rep(j, 2) cin >> A[i][j];
    cout << A[R-1][C-1] << endl;

    return 0;
} 

B - Light It Up

O(NK)
三角形の公式の問題です。
明かりを持っている人に0を代入します。
全ての明かりと点との距離を計算して、最小値を保持します。

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() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N), X(N), Y(N);
    rep(i, K) cin >> A[i];
    rep(i, N) cin >> X[i] >> Y[i];
 
    vector<double> D(N, 1e9+7);
    rep(i, K){
        int index = A[i]-1;
        double x1 = X[index];
        double y1 = Y[index];
        rep(j, N){
            if(j==index){
                D[j] = 0;
                continue;
            }
            double x2 = X[j];
            double y2 = Y[j];
            double d = sqrt( (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) );
            D[j] = min(d, D[j]);
        }
    }
    double ans=0;
    rep(i, N) ans = max(ans, D[i]);
    cout << fixed_setprecision(6) << ans << endl;
 
    return 0;
}

C - ±1 Operation 1

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() {
    ll X, A, D, N;
    cin >> X >> A >> D >> N;
    N = N - 1;

    if(X==A){
        cout << 0 << endl;
    }else{
        ll d = X - A;
        if(d>0 && D>0){
            ll r = d % D;
            ll p = d / D;
            if(p>N) r += (p - N) * D;
            else if(p+1<=N) r = min(r,D-r);
            cout << r << endl;
        }else if(d<0 && D<0){
            d = -d;
            D = -D;
            ll r = d % D;
            ll p = d / D;
            if(p>N) r += (p - N) * D;
            else if(p+1<=N) r = min(r,D-r);
            cout << r << endl;            
        }else{
            if(d<0){
                cout << -d << endl;
            }else{
                cout << d << endl;
            }
        }
    }

    return 0;
} 

C++
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