Submission #889560

#TimeUsernameProblemLanguageResultExecution timeMemory
889560rukashiiStrange Device (APIO19_strange_device)C++17
10 / 100
228 ms34268 KiB
#include <bits/stdc++.h>
using namespace std;

#define file if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }
#define int long long

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
    if (s.size()) setIn(s+".inp"), setOut(s+".out");
}

const int allmaxn = 1e6 + 2;

int n, A, B, l[allmaxn], r[allmaxn];

namespace Sub1
{
    bool Check()
    {
        int S = 0;
        for (int i = 1; i <= n; i++)
            S += (r[i] - l[i] + 1);
        return (S <= 1e6);
    }

    void solve()
    {
        set <pair <int, int>> s;
        for (int i = 1; i <= n; i++)
        {
            for (int j = l[i]; j <= r[i]; j++)
            {
                s.insert({(j + j / B) % A, j % B});
            }
        }

        cout << s.size();
    }
} // namespace Sub1

namespace Sub2
{
    bool Check()
    {
        return (n == 1);
    }

    void solve()
    {
        int len = r[1] - l[1] + 1;
        int ans = max(len % B, (len / B) % A);
        cout << ans << '\n';
    }
} // namespace Sub2


signed main()
{
    // setIO();
    file;
    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n >> A >> B;
    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i];

    if (Sub1::Check()) return Sub1::solve(), 0;
    if (Sub2::Check()) return Sub2::solve(), 0;
}

Compilation message (stderr)

strange_device.cpp: In function 'void setIn(std::string)':
strange_device.cpp:7:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | void setIn(string s) { freopen(s.c_str(), "r", stdin); }
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp: In function 'void setOut(std::string)':
strange_device.cpp:8:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | void setOut(string s) { freopen(s.c_str(), "w", stdout); }
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:4:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }
      |                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:61:5: note: in expansion of macro 'file'
   61 |     file;
      |     ^~~~
strange_device.cpp:4:86: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }
      |                                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:61:5: note: in expansion of macro 'file'
   61 |     file;
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...