QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411404#6765. Don't Really Like How The Story EndsxiaoleTL 11ms99192kbC++23962b2024-05-15 12:49:312024-05-15 12:49:31

Judging History

你现在查看的是最新测评结果

  • [2024-05-15 12:49:31]
  • 评测
  • 测评结果:TL
  • 用时:11ms
  • 内存:99192kb
  • [2024-05-15 12:49:31]
  • 提交

answer

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e6+9;const ll MOD = 1e9 + 7;
set<ll> d[Q];ll ans;
bool vis[Q];ll n,m;
ll now=1;
void dfs(ll x){
    for(auto i:d[x]){
        if(i<now+1) continue;
        if(i>now+1) break;
        if(i==now+1)
        {
            now++;
            dfs(now);
        }
    }
    if(now<n and x==1){
        ans++;
        d[now].insert(now+1);
        now=1;
        dfs(1);
    }
}
void solve(){
   cin>>n>>m;
   memset(vis,0,sizeof vis);
   ans=0;now=1;
   for (ll i = 0; i <= n; i++) d[i].clear();
   for (ll i = 0; i < m; i++)
   {
    ll o,p;cin>>o>>p;
    if(p>o) d[o].insert(p);
   }
   dfs(1);
   
   cout<<ans<<"\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 11ms
memory: 99192kb

input:

3
2 3
1 1
1 2
2 1
4 1
1 4
4 2
1 2
3 4

output:

0
2
1

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

117747
3 7
2 1
3 3
1 3
1 1
3 2
1 1
3 1
4 8
2 3
4 3
3 2
4 2
1 3
2 1
4 3
2 4
3 4
2 3
2 2
3 3
1 1
2 5
1 1
2 2
2 2
1 2
2 2
3 7
2 1
1 2
3 3
3 2
1 2
3 3
3 2
4 5
1 2
3 3
4 4
1 4
2 1
3 1
3 2
1 3
1 1
1 1
1 1
1 6
1 1
1 1
1 1
1 1
1 1
1 1
5 4
2 1
2 5
1 3
3 2
4 7
1 1
2 4
3 2
1 1
1 1
4 2
2 3
5 8
3 3
2 2
4 2
1 4
1...

output:

1
1
1
0
1
1
2
0
0
3
1
1
0
0
3
1
2
0
2
0
0
4
0
0
1
3
1
1
1
0
0
0
1
1
3
1
4
0
2
1
3
1
4
1
0
0
1
4
0
3
0
2
3
0
0
3
0
0
1
1
1
2
0
2
0
0
1
0
0
3
3
0
1
0
1
0
2
4
0
2
1
1
2
0
0
1
1
3
0
1
2
0
2
0
3
0
0
3
1
0
3
0
0
1
1
0
1
0
0
0
0
4
0
1
0
0
1
0
2
1
2
1
0
1
0
0
0
2
0
2
0
2
0
2
1
1
2
1
0
3
0
2
0
1
1
2
1
1
1
1
...

result: