답안 #962017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962017 2024-04-13T03:52:11 Z Amr 이상한 기계 (APIO19_strange_device) C++17
0 / 100
770 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=1e6+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
vector<ll> v[N];
ll npr[N];
void solve()
{
    ll n , a , b; cin >> n >> a >> b;
    multiset<ll> s;
    ll aa = a;
    for(int i = 0; i < v[a].sz; i++)
    {
        ll pr = v[a][i];
        ll cnt = 0;
        while(aa%pr==0) cnt++,aa/=pr;
        for(int k = 0; k < cnt; k++)s.insert(pr);
    }
    ll bb = (b+1);
    for(int i = 0; i < v[b+1].sz; i++)
    {
        ll pr = v[b+1][i];
        ll cnt = 0;
        while(bb%pr==0) cnt++,bb/=pr;
        for(int k = 0; k < cnt; k++)
        {
            if(s.find(pr)!=s.end()) s.erase(s.find(pr)); else break;
        }
    }
    ll dis = 1;
    for(auto it = s.begin(); it !=s.end(); it++)
        dis*=*it;
    dis*=b;
    vector<ll> vec;
    for(int i = 1; i <= n; i++)
    {
        ll l , r; cin >> l >> r;
        for(int j = l; j <= r; j++) vec.push_back(j);
    }
    ll cnt = 0;
    for(int i = 0; i < vec.sz; i++)
    {
        bool ok = 1;
        for(int j = i+1; j < vec.sz; j++)
        {
            ll dif = vec[j]-vec[i];
            if(dif%dis==0) ok = 0;
        }
        if(ok) cnt++;
    }
    cout << cnt << endl;
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    for(int i = 2; i < N; i++)
    {
        if(npr[i]==0)
        for(int j = i; j < N; j+=i)
        {
            npr[j] = 1;
            v[j].push_back(j);
        }
    }
    while(TT--)
        solve();

    return 0;
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i = 0; i < v[a].sz; i++)
      |                      ^
strange_device.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0; i < v[b+1].sz; i++)
      |                      ^
strange_device.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i = 0; i < vec.sz; i++)
      |                      ^
strange_device.cpp:69:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j = i+1; j < vec.sz; j++)
      |                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 440 ms 78672 KB Output is correct
2 Runtime error 770 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 78464 KB Output is correct
2 Runtime error 388 ms 158744 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 78440 KB Output is correct
2 Runtime error 597 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 78376 KB Output is correct
2 Runtime error 390 ms 158548 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 78376 KB Output is correct
2 Runtime error 390 ms 158548 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 78376 KB Output is correct
2 Runtime error 390 ms 158548 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 78240 KB Output is correct
2 Runtime error 596 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 440 ms 78672 KB Output is correct
2 Runtime error 770 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -