이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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));
for(int i = 0 ; i < 26 ; i ++) dp[n][i] = 1;
set<int> kat_u , kic_u;
vector<int> kat_sm(26) , kic_sm(26);
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);
}
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];
}
for(int j = 0 ; j < 26 ; j ++){
kic_sm[j] += dp[i + 1][j];
}
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();
}
컴파일 시 표준 에러 (stderr) 메시지
misspelling.cpp: In function 'void solution()':
misspelling.cpp:52:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
52 | for(int j = 0 ; j < 26 ; j ++) kat_sm[j] -= dp[(*it)][j]; it = kat_u.erase(it);
| ^~~
misspelling.cpp:52:63: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
52 | for(int j = 0 ; j < 26 ; j ++) kat_sm[j] -= dp[(*it)][j]; it = kat_u.erase(it);
| ^~
misspelling.cpp:58:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
58 | for(int j = 0 ; j < 26 ; j ++) kic_sm[j] -= dp[(*it)][j]; it = kic_u.erase(it);
| ^~~
misspelling.cpp:58:63: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
58 | for(int j = 0 ; j < 26 ; j ++) kic_sm[j] -= dp[(*it)][j]; it = kic_u.erase(it);
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |