minhahas   2년 전

다른 분들 코딩을 참고해도 통과한 코드랑 차이가 없는 것 같은데 왜 시간 초과가 뜨는지 모르겠습니다.

다른 분들 코드도 stable_sort 를 사용하고 있는데....

아래는 통과한 코드입니다.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

struct person
{
    int age;
    string name; 
};

bool compare(const person& now, const person& last)
{
    if(now.age != last.age) return now.age < last.age;
    return false;
}

int main()
{    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    person people[100001]; 

    for (int i = 0; i < N; i++) 
        cin >> people[i].age >> people[i].name;

    stable_sort(people, people + N, compare);

    for (int i = 0; i < N; i++)
        cout << people[i].age << " " << people[i].name << "\n";
}

3412mb   2년 전

std::endl을 '\n'으로 고치면 통과됩니다.

harry020606   2년 전

저도 같은 문제를 겪었는데요, endl이 엄청 느리다는 것을 이번에 깨달았습니다.

댓글을 작성하려면 로그인해야 합니다.