Submission #659131

# Submission time Handle Problem Language Result Execution time Memory
659131 2022-11-16T17:08:43 Z activedeltorre Strange Device (APIO19_strange_device) C++14
0 / 100
2 ms 1364 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
map<long long ,long long>norm;
vector<pair<long long,long long> >vec[20005];
bool cmp(pair<long long,long long> a,pair<long long,long long>b)
{
    if(a.first!=b.first)
    {
        return a.first<b.first;
    }
    return a.second>b.second;
}
int main()
{
    long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y;
    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
    {
        cin>>x>>y;
        val1=x/b;
        val2=y/b;
        rest1=x%b;
        rest2=y%b;
        if(val1==val2)
        {
            valoare=(val1*(b+1))%a;
            if(norm[valoare]==0)
            {
                cnt++;
                norm[valoare]=cnt;
            }
            vec[norm[valoare]].push_back({rest1,rest2});
        }
        else
        {
            valoare=(val1*(b+1))%a;
            if(norm[valoare]==0)
            {
                cnt++;
                norm[valoare]=cnt;
            }
            vec[norm[valoare]].push_back({rest1,b-1});
            valoare=(val2*(b+1))%a;
            if(norm[valoare]==0)
            {
                cnt++;
                norm[valoare]=cnt;
            }
            vec[norm[valoare]].push_back({0,rest2});
        }
    }
    long long suma=0,nr,dr,index;
    for(i=1;i<=cnt;i++)
    {
        sort(vec[i].begin(),vec[i].end(),cmp);
        nr=vec[i].size();
        if(nr>=1)
        {
            dr=-1;
            for(j=0;j<nr;j++)
            {
                index=j;
                dr=vec[i][j].second;
                while(dr>=vec[i][index+1].first)
                {
                    dr=max(dr,vec[i][index].second);
                    index++;
                }
                suma=suma+dr-vec[i][j].first+1;
                j=index;
            }
        }
    }
    cout<<suma;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:19:21: warning: unused variable 'm' [-Wunused-variable]
   19 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y;
      |                     ^
strange_device.cpp:19:23: warning: unused variable 'k' [-Wunused-variable]
   19 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y;
      |                       ^
strange_device.cpp:19:25: warning: unused variable 'l' [-Wunused-variable]
   19 |     long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y;
      |                         ^
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1284 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -