Submission #898055

#TimeUsernameProblemLanguageResultExecution timeMemory
898055vjudge1Misspelling (JOI22_misspelling)C++17
100 / 100
599 ms202832 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define str string #define int long long #define ll long long #define ld long double #define pb push_back #define F first #define S second #define all(x) x.begin() , x.end() #define setpr(x) cout << fixed << setprecision(x) #define endl '\n' const int inf = INT_MAX; const ld eps = 1e-9 , pi = acos(-1.0); const ll mod = 1e9 + 7; // 998244353; const int dx[4]{1 , 0 , -1 , 0} , dy[4]{0 , 1 , 0 , -1}; /* T_ai <= T_bi --> ai < bi --> S_(ai + 1 , bi) <= S_(ai , bi - 1) ai > bi --> S_(bi + 1 , ai) >= S_(bi , ai - 1) */ void solution(){ int n , m; cin >> n >> m; vector<vector<int>> kat(n + 1) , kic(n + 1) , dp(n + 1 , vector<int>(26)); vector<vector<int>> bu(n + 1); for(int i = 0 , ai , bi; i < m ; i ++){ cin >> ai >> bi; if(ai < bi) kat[ai].pb(bi); else if(ai > bi) kic[bi].pb(ai); bu[ai].pb(bi); bu[bi].pb(ai); } for(int i = 0 ; i <= n ; i ++) sort(all(bu[i])); // vector<vector<int>> bu(n + 1 , vector<int>(n + 1 , -1)); // < 1 , > 0 , = 2 // for(int i = 0 ; i < m ; i ++){ // if(a[i].F < a[i].S){ // for(int j = a[i].F + 1 ; j <= a[i].S ; j ++){ // if(bu[j][j - 1] == 0) bu[j][j - 1] = 2; // else bu[j][j - 1] = 1; // if(bu[j - 1][j] == 1) bu[j - 1][j] = 2; // else bu[j - 1][j] = 0; // } // } // else{ // for(int j = a[i].S + 1 ; j <= a[i].F ; j ++){ // if(bu[j][j - 1] == 1) bu[j][j - 1] = 2; // else bu[j][j - 1] = 0; // if(bu[j - 1][j] == 0) bu[j - 1][j] = 2; // else bu[j - 1][j] = 1; // } // } // } set<int> kat_u , kic_u; vector<int> kat_sm(26) , kic_sm(26); for(int i = 0 ; i < 26 ; i ++) dp[n][i] = 1; for(int i = n - 1 ; i >= 1 ; i --){ kat_u.insert(i + 1); kic_u.insert(i + 1); for(int j = 0 ; j < 26 ; j ++){ kat_sm[j] += dp[i + 1][j]; kic_sm[j] += dp[i + 1][j]; } // for(auto x : bu[i]){ // if(x < i){ // auto it = kic_u.lower_bound(i + 1); // while(it != kic_u.end() && (*it) <= x){ // for(int c = 0 ; c < 26 ; c ++) kic_sm[c] -= dp[(*it)][c]; // it = kic_u.erase(it); // } // } // else{ // auto it = kat_u.lower_bound(i + 1); // while(it != kat_u.end() && (*it) <= x){ // for(int c = 0 ; c < 26 ; c ++) kat_sm[c] -= dp[(*it)][c]; // it = kat_u.erase(it); // } // } // } for(auto x : kat[i]){ auto it = kat_u.lower_bound(i + 1); while(it != kat_u.end() && (*it) <= x){ for(int j = 0 ; j < 26 ; j ++) kat_sm[j] -= dp[(*it)][j]; it = kat_u.erase(it); } } for (auto x : kic[i]) { auto it = kic_u.lower_bound(i + 1); while(it != kic_u.end() && (*it) <= x){ for(int j = 0 ; j < 26 ; j ++) kic_sm[j] -= dp[(*it)][j]; it = kic_u.erase(it); } } int h = 0 , p = 0; for(int j = 0 ; j < 26 ; j ++){ dp[i][j] += h; dp[i][26 - j - 1] += p; h += kic_sm[j]; p += kat_sm[26 - j - 1]; } for(int j = 0 ; j < 26 ; j ++) dp[i][j] ++ , dp[i][j] %= mod; } int h = 0; for (int j = 0 ; j < 26 ; j ++) h += dp[1][j]; cout << h % mod; } signed main(){ IOS; int t = 1; // cin >> t; while(t --) solution(); }
#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...