Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- #include <iomanip>
- /*
- * Author: Matheus Monteiro
- */
- using namespace std;
- // #ifdef DEBUGMONTEIRO
- #define _ << " , " <<
- #define bug(x) cout << #x << " >>>>>>> " << x << endl;
- // #else
- // #define bug(x)
- // #endif
- #define int long long
- #define Max(a, b) (a > b ? a : b)
- #define Min(a, b) (a < b ? a : b)
- #define ii pair<int, int>
- #define f first
- #define s second
- #define vi vector<int>
- #define vii vector<ii>
- #define LSOne(S) ((S) & (-S))
- #define UNTIL(t) while (clock() < (t) * CLOCKS_PER_SEC)
- #define SZ(a) (int)a.size()
- #define fastio std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
- const int MAX = 200005;
- const int MOD = 1000000007; //10^9 + 7
- const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;
- const double EPS = 1e-9; //10^-9
- std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
- vector<int> kmpPreProcess(const vector<int> &t) {
- int i = 0;
- int j = -1;
- vector<int> b(t.size() + 1);
- b[0] = -1;
- while(i < t.size()) {
- while(j >= 0 && t[i] != t[j]) j = b[j];
- ++i; ++j;
- b[i] = j;
- }
- return b;
- }
- bool kmp(const vector<int> &s, const vector<int> &t) {
- vector<int> b = kmpPreProcess(t);
- int i = 0;
- int j = 0;
- while(i < s.size()) {
- while(j >= 0 && s[i] != t[j]) j = b[j];
- ++i; ++j;
- if(j == t.size()) return true;
- }
- return false;
- }
- void solve() {
- int n;
- cin >> n;
- vector<int> firstClock(n);
- for(int &w : firstClock) cin >> w;
- vector<int> secondClock(n);
- for(int &w : secondClock) cin >> w;
- sort(firstClock.begin(), firstClock.end());
- sort(secondClock.begin(), secondClock.end());
- vector<int> firstDegreeDiff;
- vector<int> secondDegreeDiff;
- for(int i = 0; i < n; ++i)
- firstDegreeDiff.push_back( ((firstClock[(i + 1) % n] - firstClock[i]) + 360000) % 360000 );
- for(int i = 0; i < n; ++i)
- secondDegreeDiff.push_back( ((secondClock[(i + 1) % n] - secondClock[i]) + 360000) % 360000 );
- for(int i = 0; i < n; ++i) firstDegreeDiff.push_back(firstDegreeDiff[i]);
- if(kmp(firstDegreeDiff, secondDegreeDiff)) {
- cout << "possible\n";
- } else {
- cout << "impossible\n";
- }
- }
- int32_t main() {
- fastio;
- int t = 1;
- //std::cin >> t;
- for(int caso = 1; caso <= t; ++caso) {
- //cout << "Case #" << caso << ": ";
- solve();
- }
- return 0;
- }
- /*
- Before submit:
- Check the corners cases
- Check solution restrictions
- For implementation solutions:
- Check the flow of the variables
- For intervals problems:
- Think about two pointers
- For complete search:
- Think about cuts
- If you get WA:
- Reread your code looking for stupid typos
- Try various manual testcases
- Recheck the correctness of your algorithm
- Reread the statement
- Write a straightforward solution, create lots of testcases by yourself, and compare both solutions
- Generate random test cases and perform a stress test, comparing your solution with the one that you are sure is correct
- Change the coder (if you're with a team)
- Give up. You may have other tasks to solve.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement