# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
657817 | cpp219 | Misspelling (JOI22_misspelling) | C++17 | 433 ms | 168236 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ld double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 5e5 + 9;
const ll mod = 1e9 + 7;
ll n,m;
vector<ll> bucs[N],bucg[N];
set<ll> alives,aliveg;
ll sumg[30],sums[30],dp[N][26];
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n>>m;
while(m--){
ll a,b; cin>>a>>b;
if (a < b) bucg[a].push_back(b);
else bucs[b].push_back(a);
}
for (ll i = 0;i < 26;i++) dp[n][i] = 1;
for (ll i = n - 1;i > 0;i--){
alives.insert(i + 1); aliveg.insert(i + 1);
for (ll j = 0;j < 26;j++)
sumg[j] += dp[i + 1][j],
sums[j] += dp[i + 1][j];
for (auto x : bucg[i]){
auto it = aliveg.lower_bound(i + 1); //debug(*it);
while(it != aliveg.end() && (*it) <= x){
for (ll j = 0;j < 26;j++) sumg[j] -= dp[(*it)][j];
it = aliveg.erase(it);
}
//exit(0);
}
//exit(0);
for (auto x : bucs[i]){
auto it = alives.lower_bound(i + 1);
while(it != alives.end() && (*it) <= x){
for (ll j = 0;j < 26;j++) sums[j] -= dp[(*it)][j];
it = alives.erase(it);
}
}
ll cur = 0;
for (ll j = 0;j < 26;j++)
dp[i][j] += cur,cur += sums[j];
cur = 0;
for (ll j = 25;j >= 0;j--)
dp[i][j] += cur,cur += sumg[j];
for (ll j = 0;j < 26;j++) dp[i][j] = (dp[i][j] + 1 + mod)%mod;
}
ll ans = 0;
for (ll j = 0;j < 26;j++) ans = (ans + dp[1][j])%mod;
cout<<ans;
}
/* be confident */
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |