Submission

Status:

PPPPPP-PPP

Subtask/Task Score:

90/100

Score: 90

User: Apimuk

Problemset: เลขดวง

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-04 08:52:16

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,day,birth;
    cin >> n >> day >> birth;
    int sunday = 1;
    if(day != 1){
        sunday = 8-day+1;
    }
    int suturn = 7;
    if(day!=7){
        suturn = 7-day+1;
    }
    vector<int> sun;
    vector<int> sutr;
    int temp= sunday;
    for(int i = 0 ;temp <=31;i++){
        sun.push_back(temp);
        temp+=7;
    }
        temp= suturn;
    for(int i = 0 ;temp <=31;i++){
        sutr.push_back(temp);
        temp+=7;
    }
    int lastday ;
    if(n == 30){
        lastday = (day+1 )% 7;
    }
    else if(n == 31){
        lastday = (day+2 )% 7;
    }
    if(lastday == 0){
        lastday = 7;
    }
    if(birth != n){
        if(find(sun.begin() , sun.end() , birth) == sun.end() && find(sutr.begin() , sutr.end() , birth) == sutr.end()){
            if(birth + 7  <=31 && birth -7 >=1){
                cout <<  birth-1 + birth +1 + birth-7 + birth+7 ;
            }
            else{
                if(birth + 7  <=31){
                    cout <<  birth-1 + birth +1 +birth+7;
                }
                else {
                    cout <<  birth-1 + birth +1 + birth-7 ;
                }
            }
        }
        else if((find(sun.begin() , sun.end() , birth) != sun.end() && find(sutr.begin() , sutr.end() , birth) == sutr.end())){
            if(birth + 7  <=31 && birth -7 >=1){
                cout <<  birth +1 + birth-7 + birth+7 ;
            }
            else{
                if(birth + 7  <=31){
                    cout << birth +1 +birth+7;
                }
                else {
                    cout << birth +1 + birth-7 ;
                }
            }
        }
        else if(find(sun.begin() , sun.end() , birth) == sun.end() && find(sutr.begin() , sutr.end() , birth) != sutr.end()){
            if(birth + 7  <=31 && birth -7 >=1){
                cout <<  birth-1  + birth-7 + birth+7 ;
            }
            else{
                if(birth + 7  <=31){
                    cout <<  birth-1  +birth+7;
                }
                else {
                    cout <<  birth-1  + birth-7 ;
                }
            }

        }

    }
    else{
        if(find(sun.begin() , sun.end() , birth) == sun.end() && find(sutr.begin() , sutr.end() , birth) == sutr.end()){
            cout << birth -1 + birth-7;
        }
        else if((find(sun.begin() , sun.end() , birth) != sun.end() && find(sutr.begin() , sutr.end() , birth) == sutr.end())){
            cout << birth -7;
        }
        else if((find(sun.begin() , sun.end() , birth) == sun.end() && find(sutr.begin() , sutr.end() , birth) != sutr.end())){
            cout << birth -7 + birth -1;
        }
    }
}