제출 #341192

#제출 시각아이디문제언어결과실행 시간메모리
341192beksultan04Marriage questions (IZhO14_marriage)C++14
44 / 100
1597 ms3436 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1e5+12;
const ll INF=1e9+7;
vector <int> g[N],v;
int m,n,ans,l;
bool vis[N],bbb[N];

bool rec(int x,int l,int r){
    if (x > m){
        ret 1;
    }
    if (bbb[x]){
        rec(x+1,l,r);
    }
    int i;
    bool f=0;
    for (i=0;i<g[x].size();++i){
        if (vis[g[x][i]] == 0 && l <= g[x][i] && g[x][i] <= r){
            vis[g[x][i]]=1;
            if (rec(x+1,l,r))f = 1;
            vis[g[x][i]]=0;
        }
    }
    ret f;
}

main(){
    int i,k,j,cnt=0;
    scan3(n,m,k)
    while (k-- ){
        int x,y;
        scan2(x,y)
        g[y].pb(x);
    }
    int l=1,r=1;
    if (g[l].size() == 1){
        vis[r]=1;
        bbb[g[l][0]] = 1;
    }
    while (r <= n){
        memset(vis,0,sizeof(vis));
        if (rec(1,l,r) == 0){
            r++;
            if (g[r].size() == 1){
                vis[r]=1;
                bbb[g[r][0]] = 1;
            }
        }
        else {
            cnt += n-r+1;
            if (g[l].size() == 1){
                vis[l]=0;
                bbb[g[l][0]] = 0;
            }
            l++;
        }
    }

    cout <<cnt;
}









컴파일 시 표준 에러 (stderr) 메시지

marriage.cpp: In function 'bool rec(int, int, int)':
marriage.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
marriage.cpp: At global scope:
marriage.cpp:48:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      |      ^
marriage.cpp: In function 'int main()':
marriage.cpp:49:9: warning: unused variable 'i' [-Wunused-variable]
   49 |     int i,k,j,cnt=0;
      |         ^
marriage.cpp:49:13: warning: unused variable 'j' [-Wunused-variable]
   49 |     int i,k,j,cnt=0;
      |             ^
marriage.cpp:16:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~
marriage.cpp:50:5: note: in expansion of macro 'scan3'
   50 |     scan3(n,m,k)
      |     ^~~~~
marriage.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~
marriage.cpp:53:9: note: in expansion of macro 'scan2'
   53 |         scan2(x,y)
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...